I have a class cTailoredReading
and a string property for an image. Right now, the below code works. When I create an instance of the class and set the datacontext
, the image control updates and shows the specified image.
However, when I call DisplayedImageChange
it isn't updating the image control.
任何建议/指示都将非常有帮助,因为我为此努力了几天。
cTailoredReading.cs:
class cTailoredReading
{
public cTailoredReading(string sTitle, string sFocus)
{
Title = sTitle;
Focus = sFocus;
Title_Image = @"C:\Users\local-paul\Pictures\Elly\3rd Birthday Photoshoot\BABY0363.JPG";
}
public void DisplayedImageChange()
{
Title_Image = @"C:\Users\local-paul\Pictures\Elly\3rd Birthday Photoshoot\BABY0364.JPG";
}
public string Title_Image { get; set; }
}
XAML:
<Image x:Name="ResourceMainImage" Source="{Binding Title_Image}" Width="80" Height="80"/>
更新
所以我尝试添加一个INotifyPropertyChanged事件,现在面对StackOverFlowException :(
cTailoredReading.cs的开头:
class cTailoredReading : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
修改后的属性
public string Title_Image {
get
{
//return @"C:\Users\local-paul\Pictures\Elly\3rd Birthday Photoshoot\BABY0364.JPG";
return this.Title_Image;
}
set
{
if (value != this.Title_Image)
{
this.Title_Image = value;
NotifyPropertyChanged();
}
}
}
您没有实现它应有的功能,请尝试以下操作: