/* 网上找的例子当双击不为同一行也会执行双击事件。综合了一下,先用这个用着,因为MenuDataGrid_LoadingRow里还有其他自动编号,统计的代码,故MenuDataGrid_LoadingRow会执行多次 缺点 e.Row.MouseLeftButtonUp -= Row_MouseLeftButtonUp; e.Row.MouseLeftButtonUp += Row_MouseLeftButtonUp; 会执行多次 */ private bool m_bFirstTime = true; void MenuDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.MouseLeftButtonUp -= Row_MouseLeftButtonUp; e.Row.MouseLeftButtonUp += Row_MouseLeftButtonUp; } private void MenuDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (MenuDataGrid.SelectedIndex == -1) { m_bFirstTime = true; } else { m_bFirstTime = false; } } private void Row_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { m_bFirstTime = !m_bFirstTime; TimeSpan t = DateTime.Now.TimeOfDay; if (this.MenuDataGrid.Tag != null) { TimeSpan oldT = (TimeSpan)this.MenuDataGrid.Tag; if ((t != oldT && (t - oldT) < TimeSpan.FromMilliseconds(300)) && !m_bFirstTime) { DoubleClick(); } } this.MenuDataGrid.Tag = t; } private void DoubleClick() { //双击操作,获取SelectItem进行操作 }
转载于:https://www.cnblogs.com/royin1088/archive/2013/01/28/2880035.html