WPF,请问ListBox模板
ListBox模板,参照的MSDN:
<Style TargetType="ListBox">
...
...
</Style>
<Style TargetType="ListBoxItem">
...
...
</Style>
问题:
上面的模板,是所有ListBox都用相同的ListBoxItem的样式吧,如果我想listBox1用一种ListBoxItem样式,
listBox2用另一种ListBoxItem样式,该怎么写呢?
[解决办法]
<Style TargetType="ListBoxItem" x:Key="ListBoxItemStyle1">
//1的样式
</Style>
<Style TargetType="ListBoxItem" x:Key="ListBoxItemStyle2">
//2的样式
</Style>
<ListBox ItemContainerStyle="{DynamicResource ListBoxStyle1}"/>
<ListBox ItemContainerStyle="{DynamicResource ListBoxStyle2}"/>
------解决方案--------------------
<ListBox ItemContainerStyle="{StaticResource Key}" .../>
或者
<ListBox ...>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
....
</Style>
</ListBox.ItemContainerStyle>
</ListBox>