WPF的TreeView添加鼠标双击事件MouseDoubleClick执行两次
Posted on 2021-07-28 10:47 Hosseini 阅读(1135) 评论(0) 编辑 收藏 举报xaml:
1 <!-- TreeViewItem --> 2 <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}"> 3 <EventSetter Event="MouseDoubleClick" Handler="MenuItem_Click" />
cs:需要做判断,防止响应两次
1 private void MenuItem_Click(object sender, RoutedEventArgs e) 2 { 3 TreeViewItem tviSender = sender as TreeViewItem; 4 if (tviSender.IsSelected) 5 MessageBox.Show("treeview被双击了"); 6 }