开发者

SendPropertyChanged of public field with private field

开发者 https://www.devze.com 2023-01-04 20:52 出处:网络
I开发者_开发百科 would like to send a property changed event of the public property everytime the private member is set.How would I do this?

I开发者_开发百科 would like to send a property changed event of the public property everytime the private member is set. How would I do this?

private string _imageName;

public string ImageName
{
    get
    {
        return _imageName;
    }
    set
    {
        _imageName = value;
        SendPropertyChanged("ImageName");
    }
}

protected virtual void SendPropertyChanged(string propertyName)
{
    if ((this.PropertyChanged != null))
    {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}


Use the property instead. Thats, what it's for

Or if you must, call SendPropertyChanged("ImageName") whenever you change the private field.

0

精彩评论

暂无评论...
验证码 换一张
取 消