I wanted to do a simple button_click that would load an animated gif and have it loop 3 times.
The closest example which is not a Winform example, is Mediaelement, but how does one load it within the button click?
Can one point me to a tutorial?
<MediaElement Height="113"
HorizontalAlignment="Left"
Name="mediaElement1"
Width="177" Source="giffy.gif"
LoadedBehavior="Play"
Stretch="Fill" SpeedRatio="1" IsMuted="False" />
I have used this one and it is easily installed via the Nuget installer into the project.
Nuget WpfAnimatedGif
Their github page WPF Animated GIF specifies how to set it to loop x number of times.
Related
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 a MediaElement full screen on a page. On top of this I have a grid that contains controls (Play,Pause etc..) and general info about the video. These controls are hidden after a few seconds of no user interaction.
If any part of the controls overlap the video being played then the entire Video is blanked out and only reappears when the controls grid is collapsed. Is it not possible to have a control of any kind over the top of a media element?
I notice that the "Video" App that comes as part of Windows8 RTM has this kind of effect over the top of a video that is playing.
UPDATE:
I've found the problem but not a solution. I'm trying to have a "Global" mediaelement so I can view it on different pages (Fullscreen, preview etc). I found this answer
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/241ba3b4-3e2a-4f9b-a704-87c7b1be7988
And followed Jim Man's suggestion to create a MediaElement on the root frame and then pull that item when needed. The issue happens as soon as I say CurrentPageMediaElement = RootFrameMediaElement
I presume it's changing the z order of the media element to that of the "Global" media element in the root frame? I'm not sure why it shows video when ControlsGrid is collapsed as the root grid is still there. If I change the root grid to have an opacity less than 1 I see the media element all the time as in the code below.
If someone has a better way to share a Global Media Element around then that would also work.
//Here I Can't See The MediaElement
<Grid Style="{StaticResource LayoutRootStyle}" Background="Black">
<MediaElement x:Name="MainMediaElement" />
<Grid x:Name="ControlsGrid" Opacity="0.7" />
</Grid>
//Here I Can See The Media Element
<Grid Style="{StaticResource LayoutRootStyle}" Background="Black" Opacity="0.7">
<MediaElement x:Name="MainMediaElement" />
<Grid x:Name="ControlsGrid" Opacity="0.7">
</Grid>
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.
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!