Reputation: 1677
I have loading.gif
file in my app. if i used jpg picture, it was shown in the app. if i used gif picture, animation is not shown. [it was been like jpg pic]
Markup:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:WebBrowser x:Name="browser" IsScriptEnabled="True" Margin="-12,0,-11,0" LoadCompleted="htmlLoadCompleted"/>
<Image x:Name="CoverImage" HorizontalAlignment="Center" Source="Assets/loading.gif" VerticalAlignment="Center"/>
</Grid>
Code :
private void htmlLoadCompleted(object sender, NavigationEventArgs e)
{
this.CoverImage.Visibility = Visibility.Collapsed;
}
Upvotes: 0
Views: 854
Reputation: 9242
install the imagetools from nuget package manager .. and add this namespace to your xaml..
xmlns:imagetools="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls"
then add this to your page resources..
<phone:PhoneApplicationPage.Resources>
<imagetools:ImageConverter x:Key="ImageConverter" />
</phone:PhoneApplicationPage.Resources>
then define image in xaml like this..
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<imagetools:AnimatedImage x:Name="CoverImage" HorizontalAlignment="Center" Source="{Binding ImageSource, Converter={StaticResource ImageConverter}}" VerticalAlignment="Center"/>
</Grid>
now do this in your code behind..
private Uri _ImageSource;
public Uri ImageSource
{
get
{
return _ImageSource;
}
set
{
_ImageSource = value;
OnPropertyChanged("ImageSource");
}
}
// Constructor
public MainPage()
{
InitializeComponent();
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
ImageSource = new Uri("/Assets/loading.gif", UriKind.Relative);
this.DataContext = this;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
it is better if you imeplement InotifyPropertyChanged in your page.cs like this.. add this to you code..
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(String str)
{
if (PropertyChanged != null)
{
PropertyChangedEventArgs e = new PropertyChangedEventArgs(str);
PropertyChanged(this, e);
}
}
and inherit your class from InotifyPropertychanged..like this..
MainPage : PhoneApplicationPage,INotifyPropertyChanged
hope this helps you..
Upvotes: 3