在Windows窗体中,它可以正常工作。但我希望它能在wpf中工作。到处搜寻,我找不到任何地方。我怎样才能使它在wpf c#
中运行 void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = this.listBox1.IndexFromPoint(e.Location);
if (index != System.Windows.Forms.ListBox.NoMatches)
{
MessageBox.Show(index.ToString());
}
}
答案 0 :(得分:0)
您可以设置自己的itemcontainer样式并使用事件设置器进行鼠标双击。
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/>
</Style>
</ListBox.ItemContainerStyle>