列表框是數據綁定的,通過xmldataprovider綁定到XML節點的集合。如何獲取WPF列表框實例中的listboxitem的索引?
1
A
回答
5
我這是回答here
基本上你設定ListBox的AlternationCount
的東西實在是高,並綁定到AlternationIndex
上類似的問題每件商品
<ListBox AlternationCount="100">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=(ItemsControl.AlternationIndex)}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
0
財產SelectedIndex
將工作。這一切都取決於你如何進行綁定
您可能想要將SelectedIndex
依賴項屬性綁定到與其datacontext相關的對象的某個屬性,例如,
<ListBox SelectedIndex="{Binding MySelectedIndex}" ItemsSource="{Binding MyItems}"/>
,但你能明顯做到這一點
<ListBox SelectedIndex="{Binding MySelectedIndex}">
<ListBoxItem>1</ListBoxItem>
<ListBoxItem>2</ListBoxItem>
<ListBoxItem>3</ListBoxItem>
<ListBoxItem>4</ListBoxItem>
</ListBox>
2
Y
ItemContainerGenerator.IndexFromContainer(my_listBoxItem);
相關問題
- 1. 獲取列表框中的ListBoxItem
- 2. 使用鼠標指針位置獲取WPF列表框中的listboxitem的索引(system.windows.control.listbox)
- 3. 如何獲取WPF ListBoxItem屬性的值
- 4. 根據列表框中的索引設置ListBoxItem的樣式
- 5. 如何獲取列表框中單擊按鈕的索引
- 6. 如何獲取列表框中所選項目的索引?
- 7. 如何獲取列表框中某個項目的索引
- 8. 如何獲取擴展選擇模式WPF列表框的索引值?
- 9. 如何從列表框中獲取列表框項目wpf
- 10. 如何從listboxitem的內容獲取索引?
- 11. 如何從列表框中獲取項目索引
- 12. 如何獲取實例屬性列表
- 13. 如何獲取WPF列表框中的選中項目?
- 14. WPF如何獲得一個ListBoxItem的
- 15. ListBoxItem上的WPF彈出框
- 16. 如何獲取列表框中選定的對象--- wpf
- 17. 獲取實例列表,Grails
- 18. 如何讓wpf listboxitem在選中時拉伸整個列表框的高度
- 19. SML - 獲取列表索引
- 20. 從列表框中的超鏈接獲取索引
- 21. 獲取列表框中的最後一個索引/值
- 22. 如何在迭代列表中獲取* .ftl中的索引
- 23. C#wpf從列表框中獲取ID
- 24. 獲取對特定WPF列表框的引用
- 25. 如何從Google表格行中獲取列的序號索引?
- 26. 如何獲取列表A-Z中某個字母的索引?
- 27. 如何從下拉列表中獲取未選定的索引?
- 28. 如何獲取列表中索引的總和?
- 29. 如何獲取Haskell列表中的元素索引
- 30. ListBox上的ListBoxItem索引mouseover
沒有理想的解決方案,雖然... – Greg 2011-04-20 14:05:18
@格雷格:您可以同時從ItemContainerGenerator得到一個ListBoxItem的指數表示同意,但它是我發現了一個ListBox做到這一點,到目前爲止的唯一途徑。我希望他們在未來版本的WPF中添加一個屬性 – Rachel 2011-04-20 14:16:02
注意:這不適用於虛擬化列表框! – punker76 2013-02-20 15:13:17