Silverlight 4.0 – StringFormat

New to Silverlight 4.0 – StringFormat provides a simple  solution for databinding in XAML and formatting the output. StringFormat is primarily used to format dates, numbers and currency values.

For example, formatting a date in a text box:

<TextBox x:Name=”dummyBox”  Text=”{Binding Path=PublishedDate, Mode=OneWay, StringFormat=’MM-dd-yyyy’}”/>

TargetNullValue can be used to set the null value for the control:

<TextBox x:Name=”dummyBox”  Text=”{Binding Path=QuantityOnHand, Mode=TwoWay, TargetNullValue=0}” />

Alternatively a FallBackValue can be set:

<TextBox x:Name=”dummyBox”  Text=”{Binding Path=SomeBindingValue, Mode=TwoWay, FallbackValue=N/A}” />

The FallbackValue displays a value when the binding operation is unsuccessful, where the TargetNullValue helps provide a value when the result of the binding value is NULL.

This entry was posted in FAQ and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>