FREE BOOK

Chapter 15: Customizing the Display

Posted by Manning Publication Free Book | Silverlight January 19, 2012
Silverlight has everything you need to format display values, convert both inbound and outbound values, provide special handling for null values and even provide fallbacks for cases when binding fails. Throughout this book, you'll see how to customize the visual representation of your data using these powerful features.

Similar to fallback values but more useful, in my opinion, is the TargetNullValue property of the binding expression. TargetNullValuexe "TargetNullValue" allows you to display a custom value when the value you've bound to is null.

In many applications, a value of null truly means something different from the value of empty or zero. In the former, it means that no value has been entered. The latter indicates that a value has been entered but it's blank or zero. To make it easier to work with, many applications disregard the null value and simply replace it with the default value for the type. This makes it easier to display in the UI but at the cost of losing the distinction.

Starting with Silverlight 4, you can preserve the null value and still have a friendly UI. Simply provide a TargetNullValue in your binding expression:
 
 
<TextBlock Text="{Binding ApprovalCode, TargetNullValue=(missing)}" />
 
In this example, when the
ApprovalCode returns null, the TextBlock will display the text "(missing)".

Total Pages : 8 45678

comments