无论你对列表做什么都应该这样做,因为ItemsControl.AlternationIndex是一个依赖属性,应该更新:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="AliceBlue" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<ListBox Name="bob" AlternationCount="2">
<ListBoxItem Content="Herald"/>
<ListBoxItem Content="Kumar" />
<ListBoxItem Content="Bill" />
<ListBoxItem Content="Dudley" />
<ListBoxItem Content="Jack" />
</ListBox>
<Button Click="Button_Click">boo</Button>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
Code Behind测试对项目的更改:
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim item1 As ListBoxItem = bob.Items(4)
bob.Items.Remove(item1)
bob.Items.Insert(0, item1)
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3110 次 |
| 最近记录: |