Browse Source

Select dropdown item on focus.

Arrow keys within the dropdown are handled by the keyboard navigation handler, so detect when this focuses a new item and select it.
Steven Kirk 8 years ago
parent
commit
2f48873184
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/Avalonia.Controls/DropDown.cs

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

@@ -96,6 +96,16 @@ namespace Avalonia.Controls
             this.UpdateSelectionBoxItem(this.SelectedItem);
         }
 
+        protected override void OnGotFocus(GotFocusEventArgs e)
+        {
+            base.OnGotFocus(e);
+
+            if (!e.Handled && e.NavigationMethod == NavigationMethod.Directional)
+            {
+                e.Handled = UpdateSelectionFromEventSource(e.Source);
+            }
+        }
+
         /// <inheritdoc/>
         protected override void OnKeyDown(KeyEventArgs e)
         {