I have the following XAML code :
<Image x:Name="armImage" Source="{Binding PlayerImage}">
</Image>
Here's what's happenning behind the scenes.I have this property :
private BitmapImage playerImage;
public BitmapImage PlayerImage
{
get { return playerImage; }
set
{
this.playerImage = value;
this.PropertyChanged(this, new PropertyChangedEventArgs("PlayerImage"));
}
}
I set it like this :
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);
}
}
Where the DisplayImage method looks like this :
private BitmapImage DisplayImage(Uri imageUri)
{
if (imageUri != null)
{
return new BitmapImage(imageUri);
}
else
{
throw new InvalidOperationException();
}
}
The issue is the following - the image in the UI doesn't change when i set the property PlayerImage.I tried doing it without the MVVM pattern and the Uri works and the image is displayed,but when I try to do it that way it doesn't work?
Your property name is PlayerImage
not PlayerImageUri
change it in PropertyChanged
call
this.PropertyChanged(this, new PropertyChangedEventArgs("PlayerImageUri"));
should be
this.PropertyChanged(this, new PropertyChangedEventArgs("PlayerImage"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.