WPF页面不支持媒体元素

WPF页面不支持媒体元素

问题描述:

我想在WPF页面加载时显示一个进度条。我用媒体元素来显示一个gif图像。下面的代码描述了我所做的。WPF页面不支持媒体元素

<Page x:Class="WpfApplication3.Page1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300" 
    Title="Page1" Loaded="Page_Loaded"> 

    <Grid> 
     <MediaElement Grid.Column="2" Grid.Row="4" Margin="0,0,47,0" HorizontalAlignment="Right" Width="80" Source="progress.gif" LoadedBehavior="Manual" Name="MP"/> 
    </Grid> 
</Page> 


private void Page_Loaded(object sender, RoutedEventArgs e) 
    { 
     MP.Play(); 
    } 

但在页面 不显示我怎样才能解决这个这个进度条。 (当我与进度条尝试也得到了同样的problm)

(它的工作原理确定窗口)

+0

您是否检查过gif资源?当你在网页浏览器中打开时,播放效果不错,如IE –

+0

是的。即使它在Windows应用程序中正常工作也 – zooha

+0

什么是你的操作系统和目标框架版本 –

您可以使用WpfAnimatedGif库使用一个简单的图像元素很容易地显示GIF动画:

How do I get an animated gif to work in WPF?

距离的NuGet下载软件包:https://www.nuget.org/packages/WpfAnimatedGif

,并设置0123的ImageBehavior.AnimatedSource附加属性元素:

<Page x:Class="WpfApplication3.Page1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300" 
     Title="Page1" 
    <Grid> 
     <Image gif:ImageBehavior.AnimatedSource="progress.gif" /> 
    </Grid> 
</Page>