What are the Binding modes in Silverlight?

There seems to always be some confusion regarding what appropriate binding to use in Silverlight. I will attempt to explain it as simply as possible.

Break your thinking up between a UI layer and a Database layer.  Don’t confuse this with how your application is actually architected – this is conceptual for the purposes of this explanation. Think UI and Data.

OneTime binding is the simplest binding. It means read the data from the database and display it on the UI. Do it once only. If the data changes, too bad, the UI will not be updated to reflect any changes. It is for read once use.

OneWay binding is used when you would like any changes in the Database to be updated in the UI layer.  This is important when you are asynchronously loading data into controls on the page. For example, say your page has a Combo Box on it. When the page loads, the Combo Box is not initially populated because you want to load that asynchronously on-demand. So on page load, you make an asynchronous call to populate the Combo Box bound property. If the property bound to the ItemsSource property is OneWay bound, then the Combo Box will be updated with the newly loaded values. Compare this with OneTime binding – if the data is not loaded when the page loads, then the Combo Box would remain empty. You may choose, however, to use OneTime binding if the data is already pre-loaded into the bound property and you do not care about further changes being immediately reflected in the Combo Box. OneWay binding is the default, so if you want OneWay binding, you don’t need to specify it.

TwoWay binding is what you use whenever you want changes to values in the UI to be updated in the database. Any input box will therefore need to be TwoWay bound. It’s that simple. One benefit of TwoWay bound is that any change in the data will also be immediately reflected in the UI. Of course, if you want to use an input box, such as a text box, but don’t want it to update the database, then you won’t need TwoWay binding. OneWay or OneTime binding would be sufficient depending on your needs.

There is also a OneWayToSource binding property available in the dot net framework. This updates the database whenever changes occur in the UI, but any change in the database will not be reflected in the UI. This is not available in Silverlight.

2 Responses to What are the Binding modes in Silverlight?

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: