【问题标题】:Media element not support in WPF PageWPF 页面中不支持媒体元素
【发布时间】:2017-03-17 05:27:05
【问题描述】:

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

<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();
    }

但此进度条未显示在页面中 我怎样才能解决这个问题。 (当我也尝试使用进度条时,遇到了同样的问题)

(在窗口中可以正常工作)

【问题讨论】:

  • 你检查过你的 gif 资源了吗?用IE等浏览器打开效果好不好
  • 是的。即使它在 Windows 应用程序中也能正常工作
  • 你的操作系统和目标框架版本是什么

标签: c# wpf progress-bar mediaelement


【解决方案1】:

您可以使用 WpfAnimatedGif 库通过简单的 Image 元素轻松显示动画 gif:

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

只需从 NuGet 下载包:https://www.nuget.org/packages/WpfAnimatedGif

并设置Image元素的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>

【讨论】:

    猜你喜欢
    • 2011-01-23
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 2019-03-23
    • 1970-01-01
    相关资源
    最近更新 更多