ListBox模板,参照的MSDN:<Style TargetType="ListBox">
...
...
</Style><Style TargetType="ListBoxItem">
...
...
</Style>问题:
上面的模板,是所有ListBox都用相同的ListBoxItem的样式吧,如果我想listBox1用一种ListBoxItem样式,
listBox2用另一种ListBoxItem样式,该怎么写呢?
...
...
</Style><Style TargetType="ListBoxItem">
...
...
</Style>问题:
上面的模板,是所有ListBox都用相同的ListBoxItem的样式吧,如果我想listBox1用一种ListBoxItem样式,
listBox2用另一种ListBoxItem样式,该怎么写呢?
<Style TargetType="ListBox" x:Key="ListBoxStyle1">
...
...
</Style><Style TargetType="ListBoxItem">
//1的样式
</Style><Style TargetType="ListBox" x:Key="ListBoxStyle2">
...
...
</Style><Style TargetType="ListBoxItem">
//2的样式
</Style><ListBox Style="{DynamicResource ListBoxStyle1}"/>
<ListBox Style="{DynamicResource ListBoxStyle2}"/>
我觉得应该是这样。
<Style TargetType="ListBox" x:Key="ListBoxStyle1">
...
...
<Style TargetType="ListBoxItem">
...
...
</Style>
</Style>
<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>