Gre*_*reg 1 data-binding wpf listbox
列表框是数据绑定,通过xmldataprovider绑定到XML节点的集合.
我有一个类似的问题在这里得到解答
基本上你将ListBox设置为AlternationCount非常高的值,并绑定到AlternationIndex每个项目上
<ListBox AlternationCount="100">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=(ItemsControl.AlternationIndex)}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
你可以得到的指数ListBoxItem从ItemContainerGenerator:
listBox.ItemContainerGenerator.IndexFromContainer(listBoxItem);
Run Code Online (Sandbox Code Playgroud)