0

I want to display a progress bar in WPF Page,when it loaded. I used media element to display a gif image. Below code describe what I did.

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

but this progress bar not showing in Page How can I fix this. (when I tried with progress bar also, got same problm)

(It works ok in window )

kAsdh
  • 356
  • 1
  • 10
  • 25

1 Answers1

0

You could use the WpfAnimatedGif library to easily display an animated gif using a simple Image element:

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

Just download the package from NuGet: https://www.nuget.org/packages/WpfAnimatedGif

And set the ImageBehavior.AnimatedSource attached property of the Image element:

<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>
Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88