从 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
希望这对你有帮助..