【发布时间】:2016-12-30 12:56:51
【问题描述】:
我在 WPF 应用程序中有一个 ListBox,它附加了一个 MouseMove 事件处理程序。我想做的是使用这个事件来获取鼠标所在项目的索引。
我的代码的简化示例:
<StackPanel>
<ListBox x:Name="MyList" MouseMove="OnMouseMove"/>
<Separator/>
<Button>Beep</Button>
</StackPanel>
public CodeBehindConstructor()
{
List<string> list = new List<string>();
list.Add("Hello");
list.Add("World");
list.Add("World"); //Added because my data does have duplicates like this
MyList.ItemsSource = list;
}
public void OnMouseMove(object sender, MouseEventArgs e)
{
//Code to find the item the mouse is over
}
【问题讨论】: