How to receive notifications when something changes in a WPF window?

I have ObservableCollection, attached to WPF ListView, and all values ​​are displayed correctly. But how can I get a notification when something that has 2-way binding changes?

Should I use the INotifyPropertyChangedsame as in Winforms? Or are there better methods for doing this?

I have seen some people suggest using dependency propertiesonline, but are not sure what to do.

+5
source share
4 answers

, , DependencyObject, DependencyProperty. POCO ( clr), INotifyPropertyChanged.

- POCOs, INotifyPropertyChanged. WPF DependencyObjects ( , , UserControls...), DependencyProperties. ViewModels, ( ). , DependencyProperties ( Equals() GetHashCode() DependencyObjects , DependencyObject ).

DependencyObject, DependencyProperties . , , , , ... ( DependencyProperties, , , , :)

: : , - WPF?, DependencyProperty, clr-, Window DependencyObject. , Visual Studio DependencyProperties.

+4

:

1) - ViewModel, , ( - ). INotifyPropertyChanged.

: Person, Name TextBox. INotifyPropertyChanged, Name.

2) , . .

: , , . , IsSpinning, ViewModel IsLoading. IsSpinning .

, ...

+2

. INotifyPropertyChanged . INotifyPropertyChanged, , .

+1

INotifyPropertyChanged .

DependencyProperties , , .

Edit: I take this back ... DependencyProperties can only be implemented in DependencyObjects (an example of this is FrameworkElement, since it comes from a UIElement that comes from Visual, which comes from DependencyObject).

If you have a UserControl, you can implement the Dependency property so that you can bind this property (in XAML) to another property. You cannot make this script using the INotifyPropertyChanged function.

+1
source

All Articles