INotifyPropertyChanged using external data bindings

I have never used INotifyPropertyChanged, and I am considering using it widely in a new application.

My question is: is it correct to use the INotifyPropertyChanged interface to provide event notifications for things other than data controls?

Apparently, from a few online examples, this interface is widely used to notify meshes and such when data changes. I have various scenarios when I need other classes to be notified of data changes in other classes, and I was wondering if you think it is cleaner to implement this interface and make a modified call on setters, or rather just create regular events.

+5
source share
8 answers

When choosing this option, I tend to use language functions over other constructs.

The serious drawback of INotifyPropertyChanged is that it provides the property name as a string when updating, and your consumer classes should parse that string and decide how to act on it.

Using events, you can provide any delegate signature that is required by the event, and consumer classes can directly affect this change.

If you look under the hood, you will find that INotifyPropertyChanged is an event anyway, so why not use the events directly?

+4

, , , , . - , ?

+2

, INotifyPropertyChanged, , , , .

+1

WPF Silverlight INotifyPropertyChanged . , INotifyPropertyChanged. |

, , .NET Framework.

INotifyPropertyChanged - , , , , , switch. , ,

0

INotifyPropertyChanged -, . , , , , PropertyChanged event , . - .

( , ). INotifyPropertyChanged . , WPF - oldscool (FrameworkElement, , ***Changed).

0

, INotifyPropertyChanged push-based .

:

. , Windows Forms …Changed ; .. Foo, FooChanged, Foo.

…Changed , , / , . , ( ) "", 50 …Changed.

INotifyPropertyChanged:

  • ...:

    public T SomeProperty
    {
        get { … }
        set
        {
            if (someProperty != value)
            {
                someProperty = value;
                NotifyPropertyChanged("SomeProperty");
            }
        }
    }
    private T someProperty;
    

    AOP (, PostSharp). , CodePlex Google Code, INotifyPropertyChanged ( - CIL); , .

  • INotifyPropertyChanging, INotifyListChanged .. , .

0

, , ,

0

I am not a fan of INPC outside the realms of the user interface, as it hides the fact that significant events are generated by instances of the object. Also, if I use your class that implements INPC, I expect all properties to send notifications, if only some of them, that there is a runtime error that may go unnoticed.

0
source

All Articles