如何获取WPF列表框实例中的listboxitem的索引? [英] How do I get the index of a listboxitem in a WPF listbox instance?
本文介绍了如何获取WPF列表框实例中的listboxitem的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
列表框是数据绑定,通过xmldataprovider绑定到一个XML节点的集合。
The listbox is databound, binding to a collection of XML nodes through xmldataprovider.
推荐答案
我有一个类似的问题回答此处
I had a similar question which was answered here
基本上,您将ListBox的 AlternationCount
设置为非常高,并绑定到 AlternationIndex
每个项目
Basically you set the ListBox's AlternationCount
to something really high, and bind to the AlternationIndex
on each item
<ListBox AlternationCount="100">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=(ItemsControl.AlternationIndex)}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这篇关于如何获取WPF列表框实例中的listboxitem的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文