In This Chapter
Understanding the purpose of data binding
Binding to controls
Creating domain objects that can be bound to data
Creating sample data for data binding
User interface elements are meant to display some kind of information to the user of a Web site. This information can be in the form of text or some other visual cue. For instance, to display a temperature value, you might display it as text or as a graphical representation of a thermometer or gauge. You might also include several other properties within the control that may provide additional information to the user. The color of the text could be Red to indicate that it is hot or Blue to indicate that it is too cold.
Whenever you write XAML to display these values, you have to set a property in your code-behind file using C# or VB.NET. For instance, if you want to use a TextBlock control to display the temperature, you may just set the
Text property on it. This is fine. But what if the value of the temperature changes? The most common way of fixing this problem is to set the property of
Text again with the updated value. And if you used the foreground color to show whether it is hot or cold, then you need to set that value as well.
If you have numerous controls, and several properties on these controls need to be changed every time the data it represents changes, the whole business can get very tedious.
Wouldn't it be nice if all you had to do was change the value, and ...