WPF ListView MouseOver Item

扶醉桌前 提交于 2019-12-25 07:52:56

问题


For the wpf listview , in the Mouse Over event how do i get a reference to the item that the mouse cursor is on ?

Regards, MadSeb


回答1:


You have to use the MouseOver event from the listViewItem that the mouse is over, not the one from the listview itself.

public MainWindow() {
    InitializeComponent();

    ListView listView = new ListView();
    ListViewItem listViewItem = new ListViewItem();

    listViewItem.MouseMove += myMouseMoveEvent;

    listView.Items.Add(listViewItem);

}

private void myMouseMoveEvent(object sender, MouseEventArgs e) {
    ListViewItem item = (ListViewItem) sender;
    // now you can handle the events with this item....
}


来源:https://stackoverflow.com/questions/4294945/wpf-listview-mouseover-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!