简体   繁体   English

XAML绑定问题中的ImageSource Windows Phone

[英]ImageSource in XAML binding issue Windows phone

I have the following XAML code : 我有以下XAML代码:

 <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 : DisplayImage方法如下所示:

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? 问题如下-当我设置属性PlayerImage时,UI中的图像没有更改。我尝试在没有MVVM模式的情况下进行操作,并且Uri正常工作并显示了图像,但是当我尝试以这种方式进行操作时不起作用?

Your property name is PlayerImage not PlayerImageUri change it in PropertyChanged call 您的属性名称是PlayerImage而不是PlayerImageUriPropertyChanged调用中PlayerImageUri更改

this.PropertyChanged(this, new PropertyChangedEventArgs("PlayerImageUri"));

should be 应该

this.PropertyChanged(this, new PropertyChangedEventArgs("PlayerImage"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM