これは他の類似の質問がいくつかあることを知っていますが、ListBoxまたはListViewで動作するようにAlternationIndexを取得することには本当に問題があります。なぜListBox AlternationIndexは常に0を返すのですか
私の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に変更すると、インデックスは正しくなりますが、アイテムコントロールは必要ありません。それに付属のすべての機能を持つリストボックスが必要です。
なぜこのようなことが起こっているのかご存じの方は、お手数をおかけします。 ListBox
またはListView
については
おかげ
キーラン
これは意味があり、ListBoxItemを参照すると完璧に動作します。ありがとうございます。 – Kezza