如何在viewmodel中获取ItemsControls的当前项索引?

时间:2013-11-14 14:14:30

标签: wpf

如何在viewmodel中获取ItemsControls的当前项索引? 我们想要使用viewmodel

中的itemscontrol中的ctrl + D删除所选的文本框项

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

2 个答案:

答案 0 :(得分:3)

正如@metacircle所提到的,您应该使用内置此功能的ListBox,而不是ItemsControl。使用ListBox,您可以使用许多选项来访问所选项目:

SelectedIndex Property

SelectedItem Property

SelectedValue Property

您可以在MSDN上的这些页面上找到代码示例,并在ListBox Class页面中找到更多示例。

答案 1 :(得分:-1)

ItemsControl没有“当前项目”或“当前索引”的概念。

您正在寻找Selector派生的控件,例如ListBox