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
2010-06-06 02:26:43
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
2010-06-07 08:01:44