0

I'm using the MediaElement to show gif image as shown below.

<MediaElement x:Name="imgLoadingImage" 
    MediaEnded="imgLoadingImage_MediaEnded" 
    UnloadedBehavior="Manual"     
    Source="file:\loading.GIF" 
    LoadedBehavior="Play" 
    Stretch="None" 
    Visibility="Visible"/>

It works fine but the transparent pixels are shown as black.

Is there anyway we can make it transparent?

kennyzx
  • 12,845
  • 6
  • 39
  • 83

2 Answers2

5

The WebBrowser option won't work with MVVM, however you can apply the animated Gif as it's own transparency mask and then it works:

<MediaElement LoadedBehavior="Play" Source="{Binding MyGif}" >
    <MediaElement.OpacityMask>
        <ImageBrush ImageSource="{Binding MyGif}"/>
    </MediaElement.OpacityMask>
</MediaElement>
Anthony Nichols
  • 1,586
  • 2
  • 25
  • 50
-1

I did a work around for this. Instead of using MediaElement control I've used WebBrowser control which can render GIF image as HTML content

    <WebBrowser x:Name="wbImage" Source="pack://siteoforigin:,,,/Images/loading.gif"/>
  • I'd check this: http://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf . Using a `WebBrowser` for this is pretty much overkill. – Jcl Jan 12 '15 at 12:14
  • Not to mention the memory leaks WebBrowser still has despite plenty of patches from MS where they could have fixed the issue. – Wobbles Jul 17 '17 at 19:32