简体   繁体   中英

Binding with StringFormat on Windows Phone 7?

I'm doing some Windows Phone 7 development and want to format a string I've bound to.

For some reason I cannot use the StringFormat like shown below. The option just isn't there.

 <TextBlock Text="{Binding Distance, StringFormat=\{0\}km}" />

Why isn't the StringFormat available for Windows Phone 7?

StringFormat was added with 7.1 / Mango since Mango uses SL4. An example from Visual Studio Magazine :

<TextBlock Text="{Binding CurrentDate,StringFormat='dddd, d MMMM yyyy'}" />

StringFormat only available in SL4 and WPF... and it's not available for WP7 beacuse it's Silverlight 3. You could use converters to format those binding. Check this link:

Formatting a date in XAML on WP7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM