我的应用中有loading.gif
个文件。如果我使用jpg图片,它显示在应用程序中。如果我使用gif图片,则不显示动画。 [它就像jpg pic]
标记:
<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>
代码:
private void htmlLoadCompleted(object sender, NavigationEventArgs e)
{
this.CoverImage.Visibility = Visibility.Collapsed;
}
答案 0 :(得分:3)
从nuget包管理器安装imagetools .. 并将此命名空间添加到您的xaml ..
xmlns:imagetools="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls"
然后将其添加到您的页面资源..
<phone:PhoneApplicationPage.Resources>
<imagetools:ImageConverter x:Key="ImageConverter" />
</phone:PhoneApplicationPage.Resources>
然后像这样在xaml中定义图像..
<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>
现在在您的代码中执行此操作..
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();
}
如果你像你这样在你的page.cs中添加InotifyPropertyChanged会更好.. 将此添加到您的代码..
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(String str)
{
if (PropertyChanged != null)
{
PropertyChangedEventArgs e = new PropertyChangedEventArgs(str);
PropertyChanged(this, e);
}
}
并从InotifyPropertychanged中继承您的类..这就是..
MainPage : PhoneApplicationPage,INotifyPropertyChanged
希望这可以帮助你..