【发布时间】:2011-11-24 10:08:37
【问题描述】:
我的 WPF ListBox 包含两种类型的对象:产品和品牌。
我希望我的产品可供选择。我想要我的品牌不可选。
这两种类型中的每一种都有自己的 DataTemplate。
默认情况下,可以选择任何东西:
<ListBox ... >
<ListBox.Resources>
<DataTemplate DataType="{x:Type local:Product}">
...
</DataTemplate>
<DataTemplate DataType="{x:Type local:Brand}">
...
</DataTemplate>
</ListBox.Resources>
</ListBox>
我可以使用 Setter 设置 Focusable,但是可能会选择 nothing:
<ListBox ... >
<ListBox.Resources>
...
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Focusable" Value="False" />
</Style>
</ListBox.Resources>
</ListBox>
我无法将 Setter 放在 DataTemplate 中。
我无法将 DataType 放到 Style 上。
如何仅设置 Brand 类型的 ListBoxItems 的样式?
【问题讨论】:
标签: wpf xaml styles datatemplate listboxitem