2

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?

1 Answers1

0

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"));
ElectricRouge
  • 1,239
  • 3
  • 22
  • 33
  • Great notice,thanks.But that doesn't solve the issue.Still getting the same result >.> – Hristo Hristov Mar 22 '14 at 21:18
  • I was wondering if the UI knows that something changed because the update source trigger on image controls doesn't contain a "Property Changed" option? – Hristo Hristov Mar 22 '14 at 21:20
  • @user3313838 UpdateSourcetrigger does contain PropertyChanged option. If you think that is a problem. you can set it like this `Source="{Binding PlayerImage,UpdateSourceTrigger=PropertyChanged}"` – ElectricRouge Mar 22 '14 at 21:25
  • I'm not getting such possiblities on the Image control - I got - "default" and "explicit" options available. – Hristo Hristov Mar 22 '14 at 21:28
  • @user3313838 I didnt notice you are developing for windows phone. It looks like Windows phone doesn't have `updatesourcetrigger`. But there is way to `updatesource` see this link http://stackoverflow.com/questions/4833100/updatesourcetrigger-propertychanged-equivalent-for-a-windows-phone-7-textbox – ElectricRouge Mar 22 '14 at 21:34