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.