Share via


Don't forget about the databinding features of Silverlight 4 that you get with Mango!

If you are a Windows Phone developer, there are some properties offered on the Binding object in SIlverlight 4, which is supported by Mango. Thse properties were not offered in Silverlight 3/Windows Phone OS 7.0. The SL4 binding properties make setting up control bindings much easier and help you avoid using a value converter in many cases.

You can set a StringFormat value on the binding to format your string in many common formats such as currency, date, time, etc . For example, if you want the string to be formatted like currency, your binding would look like this:

      Text="{Binding StringFormat=C}"

The docs for StringFormat could use some work (don't worry--I've filed a bug and they should get fixed for the next update), but meanwhile look at the following topics for more information about what your format strings should look like:

             Standard Format Strings

             Date Format Strings

You can also set the FallbackValue property that is used when the binding can't return a value. In other words, this value will display in the UI when the binding doesn't resolve.

     Text="{Binding Name, FallbackValue=No Value}"

And finally set the TargetNullValue to display a value when the underlying source value is null or nothing.

     Text="{Binding Name, TargetNullValue=n/a}"

All of these properties will show in Intellisense and speed development for you.

Enjoy!

--Cheryl

Comments

  • Anonymous
    January 03, 2012
    Hi Cheryl, I'm not ejoying DataBinding on WP-Mango at all at the moment. Did you know that it is still not possible to databind a Command to an ApplicationBarMenuItem or to an ApplicationBarIconButton? People are building things like this: appbarutils.codeplex.com to get around and keep their MVVM-ideals. Please improve the basics first. Alex