2010-10-28 48 views

回答

4

是的,這是可能的。您可以使用ListBox的AlternationCount屬性。像

<Style TargetType="{x:Type ListBoxItem}"> 
    <Style.Triggers> 
     <Trigger Property="ItemsControl.AlternationIndex" Value="0"> 
      <Setter Property="Background" Value="White"></Setter> 
     </Trigger> 
     <Trigger Property="ItemsControl.AlternationIndex" Value="1"> 
      <Setter Property="Background" Value="LightGray"></Setter> 
     </Trigger> 
     <Trigger Property="ItemsControl.AlternationIndex" Value="2"> 
      <Setter Property="Background" Value="Gray"></Setter> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

然後東西只設置你的ListBox

<ListBox AlternationCount="3" 
     ...> 
+0

謝謝,這確實起作用的AlternationCount。但是我有2個ListBox,它們都是相同的形式,都得到這個,並且兩個Listbox都得到這個着色 – user489753 2010-10-28 07:02:38

+0

這個樣式是針對ListBoxItem的,所以它將適用於所有的列表框。 – 2010-10-28 07:09:33

+0

好的,讓它工作。再次感謝 – user489753 2010-10-28 19:01:54