Browse Source
Merge pull request #1166 from JurjenBiewenga/DropdownKeyboardTweaks
Added initial changes to dropdown
pull/1270/merge
Steven Kirk
9 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
43 additions and
1 deletions
-
src/Avalonia.Controls/DropDown.cs
-
src/Avalonia.Controls/ItemsControl.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) |
|
|
|
{ |
|
|
|
@ -104,7 +114,7 @@ namespace Avalonia.Controls |
|
|
|
if (!e.Handled) |
|
|
|
{ |
|
|
|
if (e.Key == Key.F4 || |
|
|
|
(e.Key == Key.Down && ((e.Modifiers & InputModifiers.Alt) != 0))) |
|
|
|
((e.Key == Key.Down || e.Key == Key.Up) && ((e.Modifiers & InputModifiers.Alt) != 0))) |
|
|
|
{ |
|
|
|
IsDropDownOpen = !IsDropDownOpen; |
|
|
|
e.Handled = true; |
|
|
|
@ -114,6 +124,27 @@ namespace Avalonia.Controls |
|
|
|
IsDropDownOpen = false; |
|
|
|
e.Handled = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (!IsDropDownOpen) |
|
|
|
{ |
|
|
|
if (e.Key == Key.Down) |
|
|
|
{ |
|
|
|
if (SelectedIndex == -1) |
|
|
|
SelectedIndex = 0; |
|
|
|
|
|
|
|
if (++SelectedIndex >= ItemCount) |
|
|
|
SelectedIndex = 0; |
|
|
|
|
|
|
|
e.Handled = true; |
|
|
|
} |
|
|
|
else if (e.Key == Key.Up) |
|
|
|
{ |
|
|
|
if (--SelectedIndex < 0) |
|
|
|
SelectedIndex = ItemCount - 1; |
|
|
|
|
|
|
|
e.Handled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -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); |
|
|
|
|