views:

94

answers:

2

I heard that I could create a collection of mixed types and have a different Data Template for each type. How woudl I do that for a ListBox?

A: 

ItemTemplateSelector property of ListBox is made specifically for that.

repka
A: 

And you need a class inheriting from DataTemplateSelector and then override the SelectTemplate method:

public class SomeTemplateSelector:DataTemplateSelector
{
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        if(((YourDataContextClass)item).SomeLogic)
            return FirstTemplate;
        else
            return OtherTemplate;
    }
 }
Goblin