Monday, May 17, 2010

BindingBase class In SilverLight 4.0

In Silverlight 3.0 we use Converts for custom Binding format. To do we Implement the following Interface and its Two Methods.

image

Now In Silverlight 4.0 we have BindingBase class  can relieve us from writing a converter in some situation .

Here we are going to see the following three properties of BindingBase class .   TargetNullValue,StringFormat, and FallbackValue.

TargetNullValue

Here I have Contacts Class with some properties.  one of the property is Age is nullable type. suppose if Age is null we are going to display Text AgeNotknown. using TargetNullValue.

image

image
image

 

StringFormat:

Here we are going to format the Data of birth property.

image

image

FallbackValue

For example let say we have two classes Contacts and MyClassMate

image

There is a situation when an interface would bind to either an instance of Contacts or MyClassMate . The Year property is available only on MyClassMate . If we are binding an Contacts instance, no value would be displayed for this property. The FallbackValue can be used in this case to indicate that if the property is not found.

Here is XAML code to set FallbackValue.

 

image

image

Nandri(Thanks)

SreenivasaRagavan

No comments: