Browse Source

focus first item in DropDown on key up/down

pull/2122/head
Andrey Kunchev 8 years ago
parent
commit
fa8380d92d
  1. 11
      src/Avalonia.Controls/DropDown.cs

11
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. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using System.Linq;
using Avalonia.Controls.Generators; using Avalonia.Controls.Generators;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes; using Avalonia.Controls.Shapes;
@ -138,6 +139,16 @@ namespace Avalonia.Controls
e.Handled = true; 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;
}
}
} }
/// <inheritdoc/> /// <inheritdoc/>

Loading…
Cancel
Save