好的,我知道还有其他类似的问题,但我在使用ListBox或ListView时遇到了AlternationIndex无法正常工作的问题。
我的XAML如下:
<ListBox BorderThickness="0" Name="RecentItemsListBox" HorizontalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemsSource="{Binding Path=RecentFilesList}" AlternationCount="100">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=(ItemsControl.AlternationIndex),
RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource IncCnvrtr}}"
Foreground="DimGray" FontSize="20" FontWeight="Bold"
HorizontalAlignment="Left" Margin="5,5,15,5" />
<StackPanel VerticalAlignment="Center">
<TextBlock Text="{Binding ClassName}" Foreground="Black" />
<TextBlock Text="{Binding DisplayName}" Foreground="Black" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
转换器将值增加1。这很好用,我已经调试过并确认发送到转换器的值始终为0。
疯狂的是,这只对ListBox或ListView有效。
一旦我将其更改为ItemsControl,索引就是正确的,但我不想要一个ItemsControl,我想要一个带有所有附带功能的ListBox。
如果您有任何想法,为什么会发生这种情况,我将非常感激您的帮助。
谢谢
Kieran