从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 imeplement INotifyPropertyChanged的像这样.. 将此代码加入您的编码。
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(String str)
{
if (PropertyChanged != null)
{
PropertyChangedEventArgs e = new PropertyChangedEventArgs(str);
PropertyChanged(this, e);
}
}
和InotifyPropertychanged..like继承类的..
MainPage : PhoneApplicationPage,INotifyPropertyChanged
希望这可以帮助你..
我很困惑,你是在告诉图像控制崩溃 - 所以它不会被看到? ?? – OneFineDay
http://wp.qmatteoq.com/how-to-display-gif-images-in-a-windows-phone-application/ –
图像显示。但不是动画。 @DonA –