0 points

Generic c# - Raise an event whenever a property's value changed? - Stack Overflow


dashboard

Wed Jul 22 2020 21:22:57 GMT+0000 (UTC)

Posted by @AsiBela #cs

public class MyClass : INotifyPropertyChanged
{
    private string imageFullPath;

    protected void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
            handler(this, e);
    }

    protected void OnPropertyChanged(string propertyName)
    {
        OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
    }

    public string ImageFullPath
    {
        get { return imageFullPath; }
        set
        {
            if (value != imageFullPath)
            {
                imageFullPath = value;
                OnPropertyChanged("ImageFullPath");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}
content_copy Copy

https://stackoverflow.com/questions/2246777/raise-an-event-whenever-a-propertys-value-changed