From 08967132c4157dcf04b99d1fbd0ffd6fd17c120b Mon Sep 17 00:00:00 2001 From: GF-Huang Date: Fri, 27 Nov 2020 23:34:39 +0800 Subject: [PATCH] Fix issues and rename. --- .../UserControl/Styles/DataGridDemoCtl.xaml | 2 +- .../Controls/Attach/DataGridAttach.cs | 30 +++++++------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Styles/DataGridDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Styles/DataGridDemoCtl.xaml index bcd47613..e48355df 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Styles/DataGridDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Styles/DataGridDemoCtl.xaml @@ -9,7 +9,7 @@ - + diff --git a/src/Shared/HandyControl_Shared/Controls/Attach/DataGridAttach.cs b/src/Shared/HandyControl_Shared/Controls/Attach/DataGridAttach.cs index 20859135..1ede0679 100644 --- a/src/Shared/HandyControl_Shared/Controls/Attach/DataGridAttach.cs +++ b/src/Shared/HandyControl_Shared/Controls/Attach/DataGridAttach.cs @@ -312,20 +312,21 @@ namespace HandyControl.Controls /// /// 在 中点击空白地方取消选择所有 Row 和 Cell /// - public static readonly DependencyProperty ClickBlankUnselectProperty = - DependencyProperty.RegisterAttached("ClickBlankUnselect", typeof(bool), typeof(DataGridAttach), new PropertyMetadata(false, ClickBlankUnselectPropertyChanged)); + public static readonly DependencyProperty CanUnselectRowsWithBlankAreaProperty = + DependencyProperty.RegisterAttached("CanUnselectRowsWithBlankArea", typeof(bool), typeof(DataGridAttach), + new PropertyMetadata(false, OnCanUnselectRowsWithBlankAreaChanged)); - public static bool GetClickBlankUnselect(DependencyObject obj) + public static bool GetCanUnselectRowsWithBlankArea(DependencyObject obj) { - return (bool)obj.GetValue(ClickBlankUnselectProperty); + return (bool)obj.GetValue(CanUnselectRowsWithBlankAreaProperty); } - public static void SetClickBlankUnselect(DependencyObject obj, bool value) + public static void SetCanUnselectRowsWithBlankArea(DependencyObject obj, bool value) { - obj.SetValue(ClickBlankUnselectProperty, value); + obj.SetValue(CanUnselectRowsWithBlankAreaProperty, value); } - public static void ClickBlankUnselectPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + public static void OnCanUnselectRowsWithBlankAreaChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is DataGrid dataGrid && e.NewValue is bool enabled) { @@ -338,19 +339,10 @@ namespace HandyControl.Controls private static void DataGrid_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if (sender is DataGrid dataGrid) + if (sender is DataGrid dataGrid && e.OriginalSource is System.Windows.Controls.ScrollViewer) { - var dependencyObject = e.OriginalSource as DependencyObject; - while (dependencyObject != null && !(dependencyObject is DataGridRow)) - { - dependencyObject = VisualTreeHelper.GetParent(dependencyObject); - } - - if (dependencyObject == null) - { - dataGrid.CommitEdit(); - dataGrid.UnselectAll(); - } + dataGrid.CommitEdit(); + dataGrid.UnselectAll(); } } }