下载app免费领取会员
选择器:
public class MyTemplateSelector:DataTemplateSelector
{
public DataTemplate DefaultTemplate
{
get;
set;
}
public DataTemplate RedTemplate
{
get;
set;
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
TemplateSelector.ViewModel.ListItem _item = item as TemplateSelector.ViewModel.ListItem;
if (_item.Id > 3)
return RedTemplate;
return DefaultTemplate;
}
}
使用选择器:
MyTemp和RedTemp是创建好的模板
<ListBox ItemsSource="{Binding Path=Items}" >
<ListBox.ItemTemplateSelector>
<loc:MyTemplateSelector
DefaultTemplate="{StaticResource MyTemp}"
RedTemplate="{StaticResource RedTemp}"
/>
</ListBox.ItemTemplateSelector>
</ListBox>
本文版权归腿腿教学网及原创作者所有,未经授权,谢绝转载。