WPF为ListBox添加ListBoxItem的双击事件

<ListBox> .... <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"> <EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/> </Style> </ListBox.ItemContainerStyle> </ListBox>
 
在代码里实现ListBoxItem_MouseDoubleClick:

private void ListBoxItem_MouseDoubleClick(object sender,RoutedEventArgs e)
{
MessageBox.Show("ListBoxItem被双击");
}


你可能感兴趣的:(WPF为ListBox添加ListBoxItem的双击事件)