From a76d14650b8221e3a86ea3165e589c199cba2335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Sun, 23 Feb 2020 23:46:01 +0000 Subject: [PATCH 1/2] Fixed obsolete API usages. --- src/Avalonia.Controls/ContextMenu.cs | 3 +-- src/Avalonia.Input/NavigationDirection.cs | 4 ++-- src/Avalonia.Themes.Default/ComboBox.xaml | 1 - src/Avalonia.Themes.Default/MenuItem.xaml | 6 ++---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Controls/ContextMenu.cs b/src/Avalonia.Controls/ContextMenu.cs index 5dfa5863f5..fc56e26add 100644 --- a/src/Avalonia.Controls/ContextMenu.cs +++ b/src/Avalonia.Controls/ContextMenu.cs @@ -104,8 +104,7 @@ namespace Avalonia.Controls { PlacementMode = PlacementMode.Pointer, PlacementTarget = control, - StaysOpen = false, - ObeyScreenEdges = true + StaysOpen = false }; _popup.Opened += PopupOpened; diff --git a/src/Avalonia.Input/NavigationDirection.cs b/src/Avalonia.Input/NavigationDirection.cs index 406890b767..0e7e991260 100644 --- a/src/Avalonia.Input/NavigationDirection.cs +++ b/src/Avalonia.Input/NavigationDirection.cs @@ -100,12 +100,12 @@ namespace Avalonia.Input /// public static NavigationDirection? ToNavigationDirection( this Key key, - InputModifiers modifiers = InputModifiers.None) + KeyModifiers modifiers = KeyModifiers.None) { switch (key) { case Key.Tab: - return (modifiers & InputModifiers.Shift) != 0 ? + return (modifiers & KeyModifiers.Shift) != 0 ? NavigationDirection.Next : NavigationDirection.Previous; case Key.Up: return NavigationDirection.Up; diff --git a/src/Avalonia.Themes.Default/ComboBox.xaml b/src/Avalonia.Themes.Default/ComboBox.xaml index 2afed09b0c..95bd9550a5 100644 --- a/src/Avalonia.Themes.Default/ComboBox.xaml +++ b/src/Avalonia.Themes.Default/ComboBox.xaml @@ -37,7 +37,6 @@ MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}" MaxHeight="{TemplateBinding MaxDropDownHeight}" PlacementTarget="{TemplateBinding}" - ObeyScreenEdges="True" StaysOpen="False"> diff --git a/src/Avalonia.Themes.Default/MenuItem.xaml b/src/Avalonia.Themes.Default/MenuItem.xaml index 93989d3782..769ab893bf 100644 --- a/src/Avalonia.Themes.Default/MenuItem.xaml +++ b/src/Avalonia.Themes.Default/MenuItem.xaml @@ -45,8 +45,7 @@ + IsOpen="{TemplateBinding IsSubMenuOpen, Mode=TwoWay}"> @@ -95,8 +94,7 @@ + StaysOpen="True"> From acbaecd3116148c7c500eae192e773c33e931a2a Mon Sep 17 00:00:00 2001 From: Symbai <14368203+Symbai@users.noreply.github.com> Date: Thu, 27 Feb 2020 23:49:57 +0100 Subject: [PATCH 2/2] Update DataGridColumnHeader.cs --- .../DataGridColumnHeader.cs | 88 ++++++++++--------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs index bff2b500ae..31c77c595d 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs @@ -67,7 +67,7 @@ namespace Avalonia.Controls static DataGridColumnHeader() { - AreSeparatorsVisibleProperty.Changed.AddClassHandler((x,e) => x.OnAreSeparatorsVisibleChanged(e)); + AreSeparatorsVisibleProperty.Changed.AddClassHandler((x, e) => x.OnAreSeparatorsVisibleChanged(e)); } /// @@ -103,7 +103,7 @@ namespace Avalonia.Controls { get; set; - } + } internal DataGrid OwningGrid => OwningColumn?.OwningGrid; internal int ColumnIndex @@ -116,19 +116,19 @@ namespace Avalonia.Controls } return OwningColumn.Index; } - } + } internal ListSortDirection? CurrentSortingState { get; private set; - } + } private bool IsMouseOver { get; set; - } + } private bool IsPressed { @@ -158,14 +158,14 @@ namespace Avalonia.Controls && OwningGrid.DataConnection.AllowSort) { var sort = OwningColumn.GetSortDescription(); - if(sort != null) + if (sort != null) { CurrentSortingState = sort.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending; } } - PseudoClasses.Set(":sortascending", + PseudoClasses.Set(":sortascending", CurrentSortingState.HasValue && CurrentSortingState.Value == ListSortDirection.Ascending); - PseudoClasses.Set(":sortdescending", + PseudoClasses.Set(":sortdescending", CurrentSortingState.HasValue && CurrentSortingState.Value == ListSortDirection.Descending); } @@ -195,7 +195,7 @@ namespace Avalonia.Controls // completed a click without dragging, so we're sorting InvokeProcessSort(keyModifiers); handled = true; - } + } internal void InvokeProcessSort(KeyModifiers keyModifiers) { @@ -208,7 +208,7 @@ namespace Avalonia.Controls { Avalonia.Threading.Dispatcher.UIThread.Post(() => ProcessSort(keyModifiers)); } - } + } //TODO GroupSorting internal void ProcessSort(KeyModifiers keyModifiers) @@ -246,45 +246,49 @@ namespace Avalonia.Controls owningGrid.DataConnection.SortDescriptions.Clear(); } - if (sort != null) + // if ctrl is held down, we only clear the sort directions + if (!ctrl) { - newSort = sort.SwitchSortDirection(); - - // changing direction should not affect sort order, so we replace this column's - // sort description instead of just adding it to the end of the collection - int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort); - if (oldIndex >= 0) + if (sort != null) { - owningGrid.DataConnection.SortDescriptions.Remove(sort); - owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort); + newSort = sort.SwitchSortDirection(); + + // changing direction should not affect sort order, so we replace this column's + // sort description instead of just adding it to the end of the collection + int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort); + if (oldIndex >= 0) + { + owningGrid.DataConnection.SortDescriptions.Remove(sort); + owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort); + } + else + { + owningGrid.DataConnection.SortDescriptions.Add(newSort); + } } else { + string propertyName = OwningColumn.GetSortPropertyName(); + // no-opt if we couldn't find a property to sort on + if (string.IsNullOrEmpty(propertyName)) + { + return; + } + + newSort = DataGridSortDescription.FromPath(propertyName, culture: collectionView.Culture); owningGrid.DataConnection.SortDescriptions.Add(newSort); } } - else - { - string propertyName = OwningColumn.GetSortPropertyName(); - // no-opt if we couldn't find a property to sort on - if (string.IsNullOrEmpty(propertyName)) - { - return; - } - - newSort = DataGridSortDescription.FromPath(propertyName, culture: collectionView.Culture); - owningGrid.DataConnection.SortDescriptions.Add(newSort); - } } } - } + } private bool CanReorderColumn(DataGridColumn column) { - return OwningGrid.CanUserReorderColumns + return OwningGrid.CanUserReorderColumns && !(column is DataGridFillerColumn) && (column.CanUserReorderInternal.HasValue && column.CanUserReorderInternal.Value || !column.CanUserReorderInternal.HasValue); - } + } /// /// Determines whether a column can be resized by dragging the border of its header. If star sizing @@ -302,7 +306,7 @@ namespace Avalonia.Controls return false; } return column.ActualCanUserResize; - } + } private static bool TrySetResizeColumn(DataGridColumn column) { @@ -316,7 +320,7 @@ namespace Avalonia.Controls return true; } return false; - } + } //TODO DragDrop @@ -371,7 +375,7 @@ namespace Avalonia.Controls { if (_dragMode == DragMode.MouseDown) { - OnMouseLeftButtonUp_Click(args.KeyModifiers, ref handled); + OnMouseLeftButtonUp_Click(args.KeyModifiers, ref handled); } else if (_dragMode == DragMode.Reorder) { @@ -449,7 +453,7 @@ namespace Avalonia.Controls OnMouseLeave(); ApplyState(); - } + } private void DataGridColumnHeader_PointerPressed(object sender, PointerPressedEventArgs e) { @@ -577,7 +581,7 @@ namespace Avalonia.Controls { return OwningGrid.Columns.Count - 1; } - } + } /// /// Returns true if the mouse is @@ -723,7 +727,7 @@ namespace Avalonia.Controls Point targetPosition = new Point(0, 0); if (targetColumn == null || targetColumn == OwningGrid.ColumnsInternal.FillerColumn || targetColumn.IsFrozen != OwningColumn.IsFrozen) { - targetColumn = + targetColumn = OwningGrid.ColumnsInternal.GetLastColumn( isVisible: true, isFrozen: OwningColumn.IsFrozen, @@ -741,7 +745,7 @@ namespace Avalonia.Controls handled = true; } - } + } private void OnMouseMove_Resize(ref bool handled, Point mousePositionHeaders) { @@ -764,7 +768,7 @@ namespace Avalonia.Controls handled = true; } - } + } private void SetDragCursor(Point mousePosition) {