开发者

WPF: How do I get different templates based on a list-item's type?

I heard that I could create a collection of mixed types and have a d开发者_如何学编程ifferent Data Template for each type. How woudl I do that for a ListBox?


ItemTemplateSelector property of ListBox is made specifically for that.


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;
    }
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜