0

I have a usercontrol to edit some properties. Each time i close the edit mode of a single property, the usercontrol call the setter which emit the PropertyChangedEvent, independent the property has been changed.

Notice, i can't change the usercontrol.

Goal: Avoiding needless PropertyChangedEvent

Workaround: Changing the Setter:

public string foo
{
get { return _foo; }
set
{
    if(_foo==value)
        return;
    _foo=value;
    NotifyPropertyChanged();
}

But I have many properties. I refuse to change all properties in that way.

Question 1: Exists a better way than my workaround?

Question 2: If not: How can i avoid code duplicate in my properties?

Syrlia
  • 154
  • 2
  • 14
  • 1
    As to your second question, Marc Gravell posted a nice solution [here](https://stackoverflow.com/questions/1315621/implementing-inotifypropertychanged-does-a-better-way-exist) The first question I don't really understand. – Zohar Peled Jan 02 '18 at 08:12
  • 1
    There are lots of variations on the theme. See marked duplicate for examples of [using an AOP tool like PostSharp](https://stackoverflow.com/a/7063938) and of [writing your own base class](https://stackoverflow.com/a/39419253). Either way, it's not difficult to put the equality comparison into the base class, rather than repeating it in each setter. – Peter Duniho Jan 02 '18 at 08:42
  • @PeterDuniho I prefer a non third party solution. But your class NotifyPropertyChangedBase is exactly what i needed. Thanks! – Syrlia Jan 02 '18 at 09:12

0 Answers0