From fa8380d92d3c17bd517827aa0ce65bac504a14f9 Mon Sep 17 00:00:00 2001 From: Andrey Kunchev Date: Tue, 20 Nov 2018 00:52:23 +0200 Subject: [PATCH] focus first item in DropDown on key up/down --- src/Avalonia.Controls/DropDown.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Avalonia.Controls/DropDown.cs b/src/Avalonia.Controls/DropDown.cs index 8596d06d2c..c941f92449 100644 --- a/src/Avalonia.Controls/DropDown.cs +++ b/src/Avalonia.Controls/DropDown.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; +using System.Linq; using Avalonia.Controls.Generators; using Avalonia.Controls.Primitives; using Avalonia.Controls.Shapes; @@ -138,6 +139,16 @@ namespace Avalonia.Controls e.Handled = true; } } + else if (IsDropDownOpen && SelectedIndex < 0 && ItemCount > 0 && + (e.Key == Key.Up || e.Key == Key.Down)) + { + var firstChild = Presenter?.Panel?.Children.FirstOrDefault(c => c.Focusable); + if (firstChild != null) + { + firstChild.Focus(); + e.Handled = true; + } + } } ///