I like to add a WebBrowser control as a Canvas background in WPF using C#. How do I do this? I have the following code at the moment. But does not work.
<Canvas
Name="canvas"
Grid.ColumnSpan="4"
Grid.Row="1"
MouseDown="Canvas_MouseDown"
MouseMove="Canvas_MouseMove"
MouseUp="Canvas_MouseUp"
Margin="0,0,0,16"
Grid.RowSpan="3">
<Canvas.Background>
<VisualBrush>
<VisualBrush.Visual>
<WebBrowser
x:Name="wbMain"
Height="246"
Width="592" />
</VisualBrush.Visual>
</VisualBrush>
</Canvas.Background>
</Canvas>
You cannot do this. The web browser control is an Internet Explorer ActiveX wrapper with the resulting airspace issues.
However, you can draw on top of it using the <Popup> control or if you don't mind losing the interactivity, try generating an image of the web page and use it as the Canvas background.
If you are thinking about using the WPF Chrome wrapper by Chris Cavanagh, bear in mind:
It does not yet support COM-Visible (so no window.external javascript methods back to your C# code)
It has a dependency on Awesomium which is only free for non-commercial use.
It will add over 10MB to your code size as it needs to embed Chromium
The WebBrowser control isn't a standard WPF control as far as I'm aware. It's basically an embedded window with an IE control in it. I'm fairly certain you can't use it in this manner.
It's an embedded IE window, so you can't use it that way.
You CAN, however, use the chrome one that way: http://chriscavanagh.wordpress.com/2009/08/25/a-real-wpf-webbrowser/
You can also map it to a surface, animate it etc.
Related
Ultimately, what I want to achieve is a replication to some extend, of an Aero glass functionality of a WPF content control.
If I apply the BlurEffect to a StackPanel that contains a TextBlock, I will have the TextBlock's text blurred.
Consider an examples:
No blur
and with <BlurEffect Radius="5" KernelType="Gaussian"/>
But is there a WPF way to blur the background behind the panel, and not it's contents?
The background of the StackPanel is a desktop, and the window that hosts it is set to AllowTransparency="True" to allow the custom-shaped look.
no, it is not possible. The Effect is applied to the element and all its children but you can easily place the TextBlock outside the container, rather than inside it.
Normally you would use a grid like so:
<Grid>
<Border>
<Border.Effect>
<BlurEffect Radius="5" KernelType="Gaussian"/>
</Border.Effect/>
</Border>
<TextBlock .../>
</Grid>
In your example that will make no difference though. What, exactly, are you trying to blur?
What the background of the StackPanel? an ImageBrush? If so why cant you apply BlurEffect to that?
If that is not possible then try this..
1] Use an image and draw it completely over Grid as I see you dont want a TileEffect. Add BlurEffect to this Image. Make sure you fill image the uniformly.
2] Then add StackPanel with transparent background as next child in the Grid i.e. dont reverse the order of image and stackpanel.
3] Then add TextBlock in StackPanel.
OR
If you insist on using a Brush to be set as the backgrounnd of the panel then use VisualBrush that draws a blurred image as background of the stackpanel, instead of ImageBrush.
Let me know if any of these tips help.
You can use the SetWindowCompositionAttribute on a Systems.Window, but you are then forced to set the WindowStyle to "None" and implement your own native Window funtionality and handles. Also inheriting from a custom control is quite complicated. Long story short, there's BlurryControls.
You can find it via NuGet by browsing for "BlurryControls" or check out the code yourself on GitHub. Eitherway, I hope this is helpful. It uses .NET 4.5.2 and only works for Windows10, since there is no solution to this problem on Windows8, and in earlier versions (Windows7 and Vista) you can achieve this by accessing DwmEnableBlurBehindWindow.
On GitHub you will also find a sample application called BlurryWindowInvoker.
You could apply this to a Grid.
<Grid.Background>
<VisualBrush>
<VisualBrush.Visual>
<Image Source="RESOURCES/BACKGROUNDS/BACKGROUND_01.jpg">
<Image.BitmapEffect>
<BlurBitmapEffect KernelType="Gaussian" Radius="20" />
</Image.BitmapEffect>
</Image>
</VisualBrush.Visual>
</VisualBrush>
</Grid.Background>
I want to play GIF (.gif) file repeatly in WPF applications by using MediaElement controls.
Below i have attached my currently using code.
<MediaElement x:Name="recImageMedia" Height="67" Margin="43,-70,816.2,0" LoadedBehavior="Play" Source="file://C:\Users\documents\visual studio 2013\Projects\Application\TempApplication\Snapshots\recordanim.gif" Visibility="Visible" />
StackOverflow suggests at least two possible solutions to your problem. The first is to use the MediaTimeline control as referenced here
MediaTimeline SO Answer
Alternatively, you may find some use in utilising MediaElement from WPF MediaKit
WPF MediaKit SO Answer
I have WPF Application with this Grid:
<Grid Name="MiddleGrid" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<WebBrowser Name="Browser" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" />
<MediaElement Name="Media" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" LoadedBehavior="Manual" UnloadedBehavior="Stop"/>
</Grid>
And i want to make the MediaElement control to be over the Browser.
Any help how i should do it?
This is a problem with how the web browser control is implemented, and you'll see the same thing if you try to embed Windows Forms controls in a WPF control as well. Things which are not native WPF (WebBrowser is provided by the IE rendering engine, with a WPF wrapper) don't participate in WPF compositing - they're child windows, not WPF controls which participate in the WPF rendering stack. The way child windows are rendered is that WPF figures out what area they should occupy, tells them about it and off they go. What WPF doesn't attempt to do is draw any WPF controls on top of it, because they can't participate in compositing with the contents of the child window underneath.
There's some information around about WPF 4.5 solving this problem (it's called "airspace") but it looks like Microsoft took that out of the final release for some reason (guessing it wasn't ready, since it's a horrendously complicated thing to do if you consider all the stuff WPF can do with render transforms, layout transforms, visual brushes and the like).
I need to draw over the html page. Page displayed in a Frame element.
The problem is that InkCanvas does not work with Frame.
I tried to insert TextBlock instead of Frame - painting works.
Does not work:
<Frame Grid.Row="1" Source="http://google.com/"></Frame>
<InkCanvas Grid.Row="1" x:Name="inkCanvas" Background="Transparent"></InkCanvas>
Work:
<TextBlock Grid.Row="1" Margin="10" Text="Some text"></TextBlock>
<InkCanvas Grid.Row="1" x:Name="inkCanvas" Background="Transparent"></InkCanvas>
When the Frame control navigates to HTML content, the Frame control internally instantiates the native WebBrowser ActiveX control. This involves HWND interop. As a result of that the "airspace proplem" comes into play. It basically means that no WPF content can overlap that AcitveX HWND. You can partly work around this propblem by wrapping the overlay into another HWND (e.g. using Winfows Forms and ElementHost). But this solution will not allow you to have transparency in the overlay.
Another trick you could try is to use the WindowsFormsHost to host the Windows Forms Browser Control instead of using a Frame.
Last but not least you could use the Chromium WPF Webbrowser Control instead of the Frame control if you can afford it. It is based on the Awesomium library. Which unfortunately is only free for non commercial use. This is the only solution that allows you to use all the advanced WPF goodies like transformation (rotation, skew etc.), bitmapeffects or transparency etc. Width the other two solutions you are bound to a fixed opaque rectangle.
I am using Silverlight 3.0 + .Net 3.5 + VSTS 2008 + C# to develop a simple video application using MediaElement of Silverlight.
I have two videos and I want to play them at the same time (similar to picture in picture effect) -- i.e. a part of the two videos are overlapped when they are playing (the same concept of Z-Order in UI design). I want to play one MediaElement on top of the other MediaElement, and I am wondering how to assign the overlap order (similar to set Z-Order UI element, but I did not find MediaElement has Z-Order property)?
You could place your MediaElement inside of a Canvas. The Elements inside a Canvas Element inherit it's Canvas.ZIndex Attribute.
<Canvas x:Name="MediaPlayerPanel" Width="200" Height="200">
<MediaElement x:Name="Media1" Height="200" Width="200" Source="file1.wmv" Canvas.ZIndex="1" />
<MediaElement x:Name="Media2" Canvas.Top="20" Canvas.Left="20" Height="100" Width="100" Source="file2.wmv" Canvas.ZIndex="2" />
</Canvas>
This should work for you!