Sunday, March 4, 2012

Binding with StringFormat

With Silverlight, when you bind a property, you can use StringFormat to format the display.
{Binding SampleText, StringFormat='My Text: \{0\}'}

Strings

You can use StringFormat like the c# String.Format() method.

Composite Formatting

Numbers

CTo display a currency. ex: StrinFormat=C –> $300.00
NTo display a number. ex: StringFormat=N –> 33,456.56
ETo display a scientific number. ex: StringFormat=E –> 6.787653e+006
PTo display a percentage. This value must be between 0 and 1. ex: StringFormat=P –> 33.54%

Standard Numeric Format Strings
Custom Numeric Format Strings

DateTimes

FStringFormat=F –> Sunday, March 04, 2012 4:22:09 PM
GStringFormat=G –> 3/4/2012 4:22:09 PM
MStringFormat=M –> March 04

You can also use the format like “MMMM yyyy” but it must be between ‘ ex: StringFormat=’MMMM yyyy’

Standard date and Time Format Strings
Custom Date and Time Format Strings

No comments:

Post a Comment