Browse Source

Added initial changes to allow the user to change the selected item while the dropdown is closed but selected and allows the user to open the dropdown by pressing down

Jurjen Biewenga 8 năm trước cách đây
mục cha
commit
4f13d50496
2 tập tin đã thay đổi với 35 bổ sung0 xóa
  1. 24 0
      src/Avalonia.Controls/DropDown.cs
  2. 11 0
      src/Avalonia.Controls/ItemsControl.cs

+ 24 - 0
src/Avalonia.Controls/DropDown.cs

@@ -114,6 +114,30 @@ namespace Avalonia.Controls
                     IsDropDownOpen = false;
                     e.Handled = true;
                 }
+
+                if (!IsDropDownOpen)
+                {
+                    if (e.Key == Key.Right)
+                    {
+                        if (++SelectedIndex >= ItemCount)
+                            SelectedIndex = 0;
+                        
+                        e.Handled = true;
+                    }
+                    else if (e.Key == Key.Left)
+                    {
+                        if (--SelectedIndex < 0)
+                            SelectedIndex = ItemCount - 1;
+                        e.Handled = true;
+                    }
+                    else if (e.Key == Key.Down)
+                    {
+                        IsDropDownOpen = true;
+                        if (SelectedIndex == -1)
+                            SelectedIndex = 0;
+                        e.Handled = true;
+                    }
+                }
             }
         }
 

+ 11 - 0
src/Avalonia.Controls/ItemsControl.cs

@@ -11,6 +11,7 @@ using Avalonia.Controls.Presenters;
 using Avalonia.Controls.Primitives;
 using Avalonia.Controls.Templates;
 using Avalonia.Controls.Utils;
+using Avalonia.Input;
 using Avalonia.LogicalTree;
 using Avalonia.Metadata;
 
@@ -106,6 +107,12 @@ namespace Avalonia.Controls
             set { SetAndRaise(ItemsProperty, ref _items, value); }
         }
 
+        public int ItemCount
+        {
+            get;
+            private set;
+        }
+
         /// <summary>
         /// Gets or sets the panel used to display the items.
         /// </summary>
@@ -352,6 +359,10 @@ namespace Avalonia.Controls
                     RemoveControlItemsFromLogicalChildren(e.OldItems);
                     break;
             }
+            
+            int? count = (Items as IList)?.Count;
+            if (count != null)
+                ItemCount = (int)count;
 
             var collection = sender as ICollection;
             PseudoClasses.Set(":empty", collection == null || collection.Count == 0);