(X) Hide this Sign up for our next free webinar: Blend for Silverlight Developers by Gill Cleeren. June 16th, 10 am PST
Join the 3-day online training XNA for Windows Phone 7. 20% discount available for attendees of the free demo webinar on June 30.
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .
        Login with Facebook

Prism 4 Gems: Rendering Heterogeneous Collections with DataTemplateSelector

(0 votes)
0 comments   /   posted by Silverlight Show on Jan 17, 2011
Tags:   datatemplateselector , prism-4 , silverlight-4 , brian-noyes

SilverlightShow Page for all Silverlight and Windows Phone 7 (WP7) things on TwitterBrian Noyes shows you how to use the DataTemplateSelector class in Prism 4.

Source: Brian Noyes' Blog

DataTemplates in WPF have a very important feature: the DataType property that allows DataTemplates to be automatically applied to a data bound object based on its type. This feature is very similar to the implicit styles capability that WPF has had since the start that is a new feature in Silverlight 4.

Unfortunately Silverlight is still lacking this feature. In Silverlight, you have to associated a single data template with a data bound control through its template property (ItemTemplate for ItemsControl and ContentTemplate for ContentControl). When you want to bind to a heterogeneous collection of objects (that all share a common base class or interface that the collection is defined in terms of), you are kind of stuck in Silverlight if you want to write specific templates per derived type.

Comments

No comments

Add Comment

Login to comment:
  *      *       
Login with Facebook