Dear gurus, please explain the bindings. In educational articles "for dummies", leak issues are not considered at all, and an independent search for information in parts led to my confusion. What I dug:
To combat memory leaks in WPF, you need to bind to objects that implement INotifyCollectionChanged . Ok, in the case of collections, everything is clear. We bind through ObservableCollection .
But what about simple data types?
Suppose we have a simple page on which there is a text field where the user enters his name. To work with this name, we will bind it to the name field.
View:
<TextBlock Text="Ваше имя:"/> <TextBox Text="{Binding name}"/> ViewModel:
public string name {get; set;} ... this.DataContext = this; this.InitializeComponent(); According to this page, to deal with a leak, you must either implement INotifyPropertyChanged on the source object, or set the DependencyProperty property. But nowhere can I find a simple example of how to do it correctly.
Here , in the last paragraph, it is generally written:
If you use .NET Framework 4.5, then you will not have a memory leak
So how to implement data binding correctly ?
INotifyPropertyChangedwith theseINotifyPropertyChangedandDependencyPropertyand use them always in such cases? - user200141