Browse Source

Fix SelectingItemsControl multiple selection.

- Allow `SelectAll` regardless of `SelectionMode`: `SelectionMode` should only apply to user-interaction
- Don't select multiple on shift/ctrl-right click
Steven Kirk 6 years ago
parent
commit
afa38852cf
1 changed files with 9 additions and 7 deletions
  1. 9 7
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

+ 9 - 7
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@@ -469,11 +469,6 @@ namespace Avalonia.Controls.Primitives
         /// </summary>
         protected void SelectAll()
         {
-            if ((SelectionMode & (SelectionMode.Multiple | SelectionMode.Toggle)) == 0)
-            {
-                throw new NotSupportedException("Multiple selection is not enabled on this control.");
-            }
-
             UpdateSelectedItems(() =>
             {
                 _selection.Clear();
@@ -523,7 +518,14 @@ namespace Avalonia.Controls.Primitives
                     var toggle = (toggleModifier || (mode & SelectionMode.Toggle) != 0);
                     var range = multi && rangeModifier;
 
-                    if (range)
+                    if (rightButton)
+                    {
+                        if (!_selection.Contains(index))
+                        {
+                            UpdateSelectedItem(index);
+                        }
+                    }
+                    else if (range)
                     {
                         UpdateSelectedItems(() =>
                         {
@@ -582,7 +584,7 @@ namespace Avalonia.Controls.Primitives
                     }
                     else
                     {
-                        UpdateSelectedItem(index, !(rightButton && _selection.Contains(index)));
+                        UpdateSelectedItem(index);
                     }
 
                     if (Presenter?.Panel != null)