tags:

views:

169

answers:

1

I am confused between various databinding mode in WPF like, One-Way Two-Eay One-Time.. etc

plz explain these through proper scenario...

So i can easily understand when and where which mode is applicable.

+1  A: 
  • OneWay: use this when you want the data in code-behind to modify the value in your GUI
  • TwoWay: use this if you want to allow code-behind to modify the GUI value, or if you want the GUI value changed by the user to be reflected in code-behind
  • OneTime: your code-behind can set the value that is shown in your GUI once, and it will never change again. Only do this if you know you're not going to need to change the value in your code-behind.
  • OneWayToSource: This is the opposite of one way -- GUI value affects code behind value.

If you don't specify anything, then the behavior will depend on the control that you are using.

Dave
sorry for the weird formatting -- I wasn't sure how to get the right line breaks.
Dave
Thanks. it is helpful...But plz specify the TwoWay example... i want to know how its reflect the code-behind.
DATT OZA
@DATT: what do you mean by "specify"? Basically, if you set Mode=TwoWay in the XAML, when you change the GUI value, it will automatically update the C# property. But your property in code-behind needs to be implemented in a class (like a ViewModel) that implements the INotifyPropertyChanged interface. When the code-behind changes the value of the property via set, you need to call PropertyChanged so that the GUI is notified of the value change, and it will update itself automatically.
Dave