Thursday, July 5, 2012

String Format in Binding in Silverlight/WPF

StringFormat is very useful property in DataBinding in Silverilght/WPF where you can format the binding data as per your requirment without writting any futher property in your Entity.

Let's see if you want to show the logged in user info like "Logged in as XXXX".
 Usually what we do is we create two textblocks 1. For showing Logged in as and 2. for showing the data from Binding. Here I will show how you can avoid adding extra textblock.


<TextBlock Text=”{Binding UserName, StringFormat=’Logged in as \{0\}’}“/>

Let me know if you have any question regarding StringFormat. Comments are welcomed.
Cheers!
Vinod

No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog