Using templates to customize the way data is shown by controls

Normally when we ask Silverlight to visualize an object, for example a person or a customer, it will simply display the result of the ToString() method—which is, of course, a string. This can be seen when we're binding a collection of items to a ListBox. If we don't specify a value for the DisplayMemberPath property, we simply see the name of the type (unless we overloaded the ToString() method). However, it's possible to specify a template called a DataTemplate, which will be used to visualize an object. It's in fact nothing more than a block of XAML code that gets rendered when an item of a particular type is visualized.

In this recipe, we'll build a DataTemplate to render the activities ...

Get Silverlight 4 Data and Services Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.