RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Application Development Tips with Silverlight 4 Tools : Page 2

Take advantage of Silverlight 4 and Windows Communication Foundation 4 to bind data to Silverlight Data Controls.

  1. Next, create a new Silverlight 4 application and add the service reference to it.
  2. Create a Grid and then use the service reference to bind data to the Silverlight Grid.
  3. Lastly, build and execute the project

That's it!

Data-binding Improvements in Silverlight 4

Before Silverlight 4, to bind data, you were restricted to have the object (that would be used to bind data) derive from the FrameworkElement class. With Silverlight 4, you can now bind data using any object that is inhertited from DependencyObject.

Silverlight 4 introduces some other interesting new improvements in DataBinding. These include:IDataErrorInfo support, string formatting support, TargetNullValue, FallbackValue support, etc.

The following code snippet shows how String formatting can be used while binding data in Silverlight 4 controls:

<TextBox Text="{Binding DateOfBirth, StringFormat='MMM dd, yyyy', 
                        Mode=TwoWay}" />
<TextBlock Text="{Binding Salary, StringFormat='c'}" />

You can use TargetNull value while data binding to Silverlight 4 controls if the element can contain a null value. You can use FallbackValue if no data is available to bind to the data control. The following code snippet shows how TargetNull and FallbackValue can be used:

<TextBlock Text="{Binding ZipCode, TargetNullValue='(None)'}" />
<TextBlock Text="{Binding Country, FallbackValue='(Nope)'}" />

Suggested Reading

Here are a few links to that provide further references on this topic:










Windows Communication Foundation is a Microsoft framework that can be used to develop scalable, service oriented, REST-based services. There have been quite a few enhancements in WCF 4.0 that has eliminated the pain of specifying tedious configuration details to host services. In this article we have discussed the basics of WCF and Silverlight and how we can use WCF data services to bind data to Silverlight controls. Happy reading!

Joydip Kanjilal has over 10 years of industry experience with C, C++, Java, C#, VB, VC++, ASP.Net, XML, Design Patterns, UML, etc. He currently works as a senior project leader in a reputable multinational company in Hyderabad, India, and has contributed articles on .NET and related technologies to www.aspalliance.com.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date