简体   繁体   中英

What exactly is Two-way databinding in WPF?

I'm learning WPF with MVVM and for a starter, I viewed Jason Dolinger's video on MVVM . In that he mentioned, that one of the advantage of using MVVM with WPF is two-way data binding. My question is what does he mean by two-way data binding? Is that the feature of ability to 1) bind data from controls(View) to properties in VM and 2) any change in collections or properties are reflected in the view? If I'm wrong, can anyone please explain me in detail what it is and what are its advantages? This might be a very simple doubt, but I'm very new to WPF and it's terminologies and moving away from WinForms now.

You're not wrong. Two way data binding has exactly that meaning.
You have the view connected with its ViewModel, so every change you make in one of them is reflected into the other.
To obtain that kind of behavior, you have to implement the interface INotifyPropertyChange in your ViewModel or using Dependency Properties, instead of normal CLR properties.
You can also use other types of data binding, like one way or one way to source. The default however is two-way.
Hope this helps. Regards

The general idea is that not only is any change to the DataContext reflected in the UI but also changes to the UI are pushed back into the DataContext.

So you are right :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM