ImageSource不会改变

本文关键字:改变 ImageSource | 更新日期: 2023-09-27 18:16:57

My XAML:

<Button Click="LikePost" BorderThickness="0" >
    <Image Stretch="Uniform" Source="{Binding imagesource}" />
</Button>

第一次设置图像资源按预期工作,但每当我在代码中更新源字符串时,XAML不会更新,是的,我已经包含了INotifyPropertyChanghed:

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));
    }
}

我做错了什么?

ImageSource不会改变

如果你发送了错误的属性名,修改这个:

NotifyLikeImageChanged("like");

:

NotifyLikeImageChanged("imagesource");