-
Book Overview & Buying
-
Table Of Contents
MCTS: Microsoft Silverlight 4 Development (70-506) Certification Guide
By :
New to Silverlight 4 is the ability to format bound data using the StringFormat property that we all know and love from .NET. Using the StringFormat property when doing data binding is perfect for when you wish to format the value that returns from the bind in a specific way, such as currency or any numerical format. Using StringFormat is pretty straightforward; just add the StringFormat property after the binding declaration, just like you did with the mode earlier:
<TextBlock Text="{Binding Price, StringFormat=c}"/>
The preceding line of code will format the Price property to a currency, which on my machine translates to 5.00$. But why did it choose the dollar symbol and not any other currency symbol? The reason for that is that formatting picks up on the default culture of the system. As my default culture is en-US, I get the dollar symbol. If I had my culture set as he-IL, I would have got the New Israeli Shekel (NIS) symbol.
Currency is just one example of use...
Change the font size
Change margin width
Change background colour