我的 XAML:
<Button Click="LikePost" BorderThickness="0" >
<Image Stretch="Uniform" Source="{Binding imagesource}" />
</Button>
第一次设置图像源按预期工作,但每当我更新代码中的源字符串时,XAML 不会更新,是的,我已经包含了 INotifyPropertyChanged:
public class Item : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _imagesource;
public string imagesource
{
get { return _imagesource; }
set
{
if (_imagesource == value) return;
_imagesource = value;
NotifyLikeImageChanged("like");
}
}
private void NotifyLikeImageChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
我做错了什么?