OneTime, OneWay and TwoWay Binding for Windows Phone

19 sep. 2018
Intermediate
10,2K Views
2 min read  

Most Windows Phone apps display data to user by using controls, from business object or a collection of business objects such as a list of contact numbers, news headlines, or images. These controls contain data by using data binding. In this article, I would like to share the different types of data binding for windows phone.

Types of Data Binding for Windows Phone

We have three types of data bonding for windows phone which determines how and when the data flows.

  1. OneTime Data Binding

    This binding mode update the dependent target control's property with the source object property only one time when the binding is created mean when your phone app starts or when you set DataContext property. This type of mode can be used when you want to display data for first time only.

    <TextBlock Text="{Binding ID, Mode=OneTime}" />
    
  2. OneWay Data Binding

    This binding mode update the dependent target control's property with the source object property when the binding is created and anytime the source object property changes. This is the default binding for any control. In this binding mode target control's property updated only when source property changed.

    <TextBlock Text="{Binding ID, Mode=OneWay}" />
    <TextBox Text="{Binding Name, Mode=OneWay}" />
    
  3. TwoWay Data Binding

    This binding mode update both the dependent target control's property and the source object property when either changes, It means when source object property changed it will update target control's property and when target control's property changed will update source object property.

    <TextBox Text="{Binding Name, Mode=TwoWay}" />
    

Note

  1. For OneWay and TwoWay binding, the source object must implement the INotifyPropertyChanged interface.

  2. Use OneTime binding when you want to display data for first time only. It usually used with TextBlock.

  3. Use OneWay binding when you want to display changed source data each time. It usually used with TextBlock.

  4. Use TwoWay binding when you want to persist change occurs either of source or target property. It usually used with TextBox.

What do you think?

I hope you will enjoy the tips while binding data to your windows phone app controls. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 8th time in a row (2016-2023). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Learn to Crack Your Technical Interview

Accept cookies & close this