MadSeb
MadSeb

Reputation: 8234

WPF ListView MouseOver Item

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

Upvotes: 1

Views: 7882

Answers (1)

tk--
tk--

Reputation: 114

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....
}

Upvotes: 3

Related Questions