這個解決方案很簡單:
如果你想爲所有的項目相同的顏色,然後通過以下方式將是合適的:
<ListView Height="768" Width="220" Background="Silver">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Foreground" Value="Blue"></Setter>
</Style>
</ListView.ItemContainerStyle>
<system:String>Item 1</system:String>
<system:String>Item 2</system:String>
<system:String>Item 3</system:String>
</ListView>
爲了特定項目有獨特的色彩,你應該把AlternationCount
屬性爲ListView本身:
<ListView AlternationCount="50" Height="768" Width="220" Background="Silver">
和內ItemContainerStyle
觸發。這裏的觸發Value
性質的物品的指標:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Foreground" Value="Red"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Foreground" Value="Blue"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="2">
<Setter Property="Foreground" Value="Black"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
在這一點上很容易弄清楚如何操作比Foreground
其他屬性。
作爲獎勵問題...哈哈 –