From c4ab6648338e14489c27e5aef49f2f863e34c3c7 Mon Sep 17 00:00:00 2001 From: Andrey Kunchev Date: Tue, 20 Nov 2018 13:34:29 +0200 Subject: [PATCH] Use Adorner Focus styling for focused DropDownItem --- src/Avalonia.Controls/DropDown.cs | 10 ++++++---- src/Avalonia.Themes.Default/DropDown.xaml | 20 ++++++++++--------- src/Avalonia.Themes.Default/DropDownItem.xaml | 5 ----- src/Avalonia.Themes.Default/FocusAdorner.xaml | 5 +++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Avalonia.Controls/DropDown.cs b/src/Avalonia.Controls/DropDown.cs index d17089c127..2197047936 100644 --- a/src/Avalonia.Controls/DropDown.cs +++ b/src/Avalonia.Controls/DropDown.cs @@ -165,10 +165,10 @@ namespace Avalonia.Controls else if (IsDropDownOpen && SelectedIndex < 0 && ItemCount > 0 && (e.Key == Key.Up || e.Key == Key.Down)) { - var firstChild = Presenter?.Panel?.Children.FirstOrDefault(c => c.Focusable); + var firstChild = Presenter?.Panel?.Children.FirstOrDefault(c => CanFocus(c)); if (firstChild != null) { - firstChild.Focus(); + FocusManager.Instance?.Focus(firstChild, NavigationMethod.Directional); e.Handled = true; } } @@ -223,7 +223,7 @@ namespace Avalonia.Controls private void PopupClosed(object sender, EventArgs e) { - if (Focusable) + if (CanFocus(this)) { Focus(); } @@ -246,13 +246,15 @@ namespace Avalonia.Controls if (IsDropDownOpen && selectedIndex != -1) { var container = ItemContainerGenerator.ContainerFromIndex(selectedIndex); - if (container != null && container.Focusable) + if (container != null && CanFocus(container)) { container.Focus(); } } } + private bool CanFocus(IControl control) => control.Focusable && control.IsEnabledCore && control.IsVisible; + private void UpdateSelectionBoxItem(object item) { var contentControl = item as IContentControl; diff --git a/src/Avalonia.Themes.Default/DropDown.xaml b/src/Avalonia.Themes.Default/DropDown.xaml index 9603bba107..ad2be275d6 100644 --- a/src/Avalonia.Themes.Default/DropDown.xaml +++ b/src/Avalonia.Themes.Default/DropDown.xaml @@ -39,15 +39,17 @@ StaysOpen="False"> - - + + - + + @@ -58,4 +60,4 @@ - \ No newline at end of file + diff --git a/src/Avalonia.Themes.Default/DropDownItem.xaml b/src/Avalonia.Themes.Default/DropDownItem.xaml index a15e770bf5..f542a34d71 100644 --- a/src/Avalonia.Themes.Default/DropDownItem.xaml +++ b/src/Avalonia.Themes.Default/DropDownItem.xaml @@ -4,7 +4,6 @@ - - - diff --git a/src/Avalonia.Themes.Default/FocusAdorner.xaml b/src/Avalonia.Themes.Default/FocusAdorner.xaml index 573c43dc8d..2d5e369573 100644 --- a/src/Avalonia.Themes.Default/FocusAdorner.xaml +++ b/src/Avalonia.Themes.Default/FocusAdorner.xaml @@ -3,7 +3,8 @@ + StrokeDashArray="1,2" + Margin="1"/> - \ No newline at end of file +