listview的WPF MouseMove事件

时间:2013-02-07 06:01:02

标签: c# wpf listview mousemove

在我的wpf应用程序中,当鼠标移动到mousemove事件中的不同项目时,我面临从listview获取项目的问题。     比如说listview包含列为的项目,

    "one"
    "two"
    "three"
    ----

Then in mousemove event if my mouse moved over the item two then i have to get "two" in my code.

Please help me as i am very new to this WPF.
Regards
Ravi

1 个答案:

答案 0 :(得分:2)

这可能是一个非常简单的解决方案,但它似乎做了你想要它做的事情。

    private void listView_MouseMove(object sender, MouseEventArgs e)
    {
        var item = Mouse.DirectlyOver;

        if (item != null && item is TextBlock)
            Debug.Print((item as TextBlock).Text);
    }

我希望这会有所帮助。