简体   繁体   English

WPF列表框项目信息

[英]WPF Listbox item information

For each item in my listbox, I have a Button and a TextBlock . 对于列表框中的每个项目,我都有一个Button和一个TextBlock I can set my button to raise an event that removes an item from the ListBox, if I click on the TextBlock to highlight the item and then Remove(myListBox.SelectedItem) . 如果我单击TextBlock突出显示该项目,然后单击Remove(myListBox.SelectedItem) ,则可以设置按钮引发一个事件,该事件将其从ListBox中Remove(myListBox.SelectedItem)

However, I'm looking for a way to identify which item in the ListBox a specific Remove-Button is attached to, so I can RemoveAt(?) when the event is raised. 但是,我正在寻找一种方法来标识特定的Remove-Button附加到ListBox中的哪个项目,以便在引发事件时可以使用RemoveAt(?)

Edit: Each of the buttons should remove the item on the line of that button without highlighting the line first. 编辑:每个按钮应删除该按钮行上的项目,而无需先突出显示该行。 Therefore, using ListBox.SelectedItem is not a viable option :) 因此,使用ListBox.SelectedItem不是一个可行的选择:)

您可以使用IndexOf方法获取项目的索引:

YourCollection.RemoveAt(YourCollection.IndexOf(myListBox.SelectedItem));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM