WPF Data Binding Modes Tutorial and Samples


Windows presentation foundation (WPF) data binding mode provides direction of data flow between source property and target property. Once you set Binding Object to target property and configure it properly you are set for data flow between source and target.

There are basically four modes with which data can travel in data binding:

1. OneTime

2. OneWay

3. TwoWay

4. OneWayToSource

If you do not set any then default mode is applied. Now default  mode depends on the target property type. If its label then default will be OneWay , if it is editable like text box then it will be TwoWay.



You have to basically decide if you want to track changes of source property or destination property or both. If you need change only on time or continuous. If you just need database values to be displayed on user interface in read only manner then use OneWay mode of Data Binding. If you use two way then you can save data back to database.

Example of Data Binding Mode:

You can either set binding through code by creating object of Binding class or through code. Both actually apply same binding. Here is the XAML way.

TextBlock Text=”{Binding ElementName=mySourceElement,Path=Text,Mode=OneWay }”

Leave a Reply

Your email address will not be published. Required fields are marked *