ImageSource在XAML绑定问题Windows phone
本文关键字:Windows phone 问题 绑定 XAML ImageSource | 更新日期: 2023-09-27 17:52:12
我有以下XAML代码:
<Image x:Name="armImage" Source="{Binding PlayerImage}">
</Image>
这是幕后发生的事情。我有这个属性:
private BitmapImage playerImage;
public BitmapImage PlayerImage
{
get { return playerImage; }
set
{
this.playerImage = value;
this.PropertyChanged(this, new PropertyChangedEventArgs("PlayerImage"));
}
}
我这样设置:
private void GameStarted(object sender, EventArgs.GameStartedEventArgs e)
{
if (e.IsUIHidden)
{
MainPlayer = new Player(0, new Uri("/Images/arm.bmp", UriKind.Relative));
this.PlayerImage = DisplayImage(MainPlayer.ImageUri);
}
}
其中DisplayImage方法看起来像这样:
private BitmapImage DisplayImage(Uri imageUri)
{
if (imageUri != null)
{
return new BitmapImage(imageUri);
}
else
{
throw new InvalidOperationException();
}
}
问题如下-当我设置属性PlayerImage时,UI中的图像不会改变。我尝试在没有MVVM模式的情况下这样做,Uri工作,图像显示,但是当我尝试这样做时,它不起作用?
您的属性名称是PlayerImage
而不是PlayerImageUri
更改为PropertyChanged
呼叫
this.PropertyChanged(this, new PropertyChangedEventArgs("PlayerImageUri"));
应该this.PropertyChanged(this, new PropertyChangedEventArgs("PlayerImage"));