开发者

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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜