2017-03-17 68 views
0

我想在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

什麼是你的操作系統和目標框架版本 –

回答

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>