Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Silverlight support StringFormat in binding?

I know that WPF 3.5 SP1 supports a StringFormat in a binding, but can Silverlight do the same? I thought it could, but damned if I can make it work!

Here's a snippet of my XAML:

<TextBlock Text="{Binding StartTime, StringFormat=t}" />

It compiles OK, but I get a runtime error when it gets to the browser...

like image 689
Craig Shearer Avatar asked Dec 29 '08 19:12

Craig Shearer


2 Answers

I don't know which version of Silverlight introduced it, but you now can. I'm using Silverlight 4 Beta.

   <data:DataGridTextColumn Header="Date" 
     Binding="{Binding CreateDt, StringFormat=\{0:d\}}" />

http://blog.davemdavis.net/2009/12/silverlight-4-data-binding-string.html

Here's info on Formatting Types, and more for DateTime.

Here's full documentation on Silverlight Binding.

like image 199
Simon_Weaver Avatar answered Oct 18 '22 15:10

Simon_Weaver


Silverlight 3 and below do not, but you can use a Value Converter and specify the ConverterParamenter in the binding. You'll have to create your own Value Converter by deriving a class from IValueConverter like I've shown here.

Silverlight 4 and later has the same StringFormat binding property as WPF.

like image 37
Michael S. Scherotter Avatar answered Oct 18 '22 16:10

Michael S. Scherotter