Browse Source

ComboBox: add focusvisual pseudoclass to replace focus adorner

pull/4209/head
Maksym Katsydan 6 years ago
parent
commit
82bd3564a5
  1. 15
      src/Avalonia.Controls/ComboBox.cs
  2. 8
      src/Avalonia.Themes.Fluent/ComboBox.xaml

15
src/Avalonia.Controls/ComboBox.cs

@ -262,6 +262,21 @@ namespace Avalonia.Controls
_popup.Closed += PopupClosed;
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
if (e.NavigationMethod == NavigationMethod.Tab
|| e.NavigationMethod == NavigationMethod.Directional)
{
PseudoClasses.Set(":focusvisual", true);
}
}
protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
PseudoClasses.Set(":focusvisual", false);
}
/// <summary>
/// Called when the ComboBox popup is closed, with the <see cref="PopupClosedEventArgs"/>
/// that caused the popup to close.

8
src/Avalonia.Themes.Fluent/ComboBox.xaml

@ -191,20 +191,20 @@
</Style>
<!-- Focused State -->
<Style Selector="ComboBox:focus /template/ Border#HighlightBackground">
<Style Selector="ComboBox:focusvisual /template/ Border#HighlightBackground">
<Setter Property="IsVisible" Value="True" />
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxBackgroundBorderBrushFocused}" />
</Style>
<Style Selector="ComboBox:focus /template/ ContentControl#ContentPresenter">
<Style Selector="ComboBox:focusvisual /template/ ContentControl#ContentPresenter">
<Setter Property="TextBlock.Foreground" Value="{DynamicResource ComboBoxForegroundFocused}" />
</Style>
<Style Selector="ComboBox:focus /template/ TextBlock#PlaceholderTextBlock">
<Style Selector="ComboBox:focusvisual /template/ TextBlock#PlaceholderTextBlock">
<Setter Property="TextBlock.Foreground" Value="{Binding PlaceholderForeground, RelativeSource={RelativeSource TemplatedParent}, TargetNullValue={DynamicResource ComboBoxForegroundFocused}}" />
</Style>
<Style Selector="ComboBox:focus /template/ Path#DropDownGlyph">
<Style Selector="ComboBox:focusvisual /template/ Path#DropDownGlyph">
<Setter Property="Fill" Value="{DynamicResource ComboBoxDropDownGlyphForegroundFocused}" />
</Style>

Loading…
Cancel
Save