Browse Source
Merge pull request #10415 from AvaloniaUI/DefaultFocusAdornerProperty
Add DefaultFocusAdornerProperty and set for themes
pull/10463/head
Max Katz
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with
41 additions and
27 deletions
-
src/Avalonia.Controls/Control.cs
-
src/Avalonia.Controls/Primitives/AdornerLayer.cs
-
src/Avalonia.Themes.Fluent/Controls/AdornerLayer.xaml
-
src/Avalonia.Themes.Fluent/Controls/FluentControls.xaml
-
src/Avalonia.Themes.Simple/Controls/AdornerLayer.xaml
-
src/Avalonia.Themes.Simple/Controls/FocusAdorner.xaml
-
src/Avalonia.Themes.Simple/Controls/SimpleControls.xaml
|
|
|
@ -403,7 +403,7 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
if (_focusAdorner == null) |
|
|
|
{ |
|
|
|
var template = GetValue(FocusAdornerProperty); |
|
|
|
var template = GetValue(FocusAdornerProperty) ?? adornerLayer.DefaultFocusAdorner; |
|
|
|
|
|
|
|
if (template != null) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -34,6 +34,12 @@ namespace Avalonia.Controls.Primitives |
|
|
|
public static readonly AttachedProperty<Control?> AdornerProperty = |
|
|
|
AvaloniaProperty.RegisterAttached<AdornerLayer, Visual, Control?>("Adorner"); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="DefaultFocusAdorner"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<ITemplate<Control>?> DefaultFocusAdornerProperty = |
|
|
|
AvaloniaProperty.Register<Control, ITemplate<Control>?>(nameof(DefaultFocusAdorner)); |
|
|
|
|
|
|
|
private static readonly AttachedProperty<AdornedElementInfo?> s_adornedElementInfoProperty = |
|
|
|
AvaloniaProperty.RegisterAttached<AdornerLayer, Visual, AdornedElementInfo?>("AdornedElementInfo"); |
|
|
|
|
|
|
|
@ -86,6 +92,15 @@ namespace Avalonia.Controls.Primitives |
|
|
|
visual.SetValue(AdornerProperty, adorner); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the default control's focus adorner.
|
|
|
|
/// </summary>
|
|
|
|
public ITemplate<Control>? DefaultFocusAdorner |
|
|
|
{ |
|
|
|
get => GetValue(DefaultFocusAdornerProperty); |
|
|
|
set => SetValue(DefaultFocusAdornerProperty, value); |
|
|
|
} |
|
|
|
|
|
|
|
private static void AdornerChanged(AvaloniaPropertyChangedEventArgs<Control?> e) |
|
|
|
{ |
|
|
|
if (e.Sender is Visual visual) |
|
|
|
|
|
|
|
@ -1,14 +1,11 @@ |
|
|
|
<Styles xmlns="https://github.com/avaloniaui" |
|
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
|
|
|
<Styles.Resources> |
|
|
|
<Thickness x:Key="SystemControlFocusVisualMargin">0</Thickness> |
|
|
|
<Thickness x:Key="SystemControlFocusVisualPrimaryThickness">2</Thickness> |
|
|
|
<Thickness x:Key="SystemControlFocusVisualSecondaryThickness">1</Thickness> |
|
|
|
</Styles.Resources> |
|
|
|
|
|
|
|
<!-- HighVisibility FocusAdorner --> |
|
|
|
<Style Selector=":is(Control)"> |
|
|
|
<Setter Property="FocusAdorner"> |
|
|
|
<ResourceDictionary xmlns="https://github.com/avaloniaui" |
|
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
|
|
|
<Thickness x:Key="SystemControlFocusVisualMargin">0</Thickness> |
|
|
|
<Thickness x:Key="SystemControlFocusVisualPrimaryThickness">2</Thickness> |
|
|
|
<Thickness x:Key="SystemControlFocusVisualSecondaryThickness">1</Thickness> |
|
|
|
|
|
|
|
<ControlTheme x:Key="{x:Type AdornerLayer}" TargetType="AdornerLayer"> |
|
|
|
<Setter Property="DefaultFocusAdorner"> |
|
|
|
<FocusAdornerTemplate> |
|
|
|
<Border BorderThickness="{DynamicResource SystemControlFocusVisualPrimaryThickness}" |
|
|
|
BorderBrush="{DynamicResource SystemControlFocusVisualPrimaryBrush}" |
|
|
|
@ -18,5 +15,5 @@ |
|
|
|
</Border> |
|
|
|
</FocusAdornerTemplate> |
|
|
|
</Setter> |
|
|
|
</Style> |
|
|
|
</Styles> |
|
|
|
</ControlTheme> |
|
|
|
</ResourceDictionary> |
|
|
|
@ -4,6 +4,7 @@ |
|
|
|
<Styles.Resources> |
|
|
|
<ResourceDictionary> |
|
|
|
<ResourceDictionary.MergedDictionaries> |
|
|
|
<MergeResourceInclude Source="avares://Avalonia.Themes.Fluent/Controls/AdornerLayer.xaml" /> |
|
|
|
<MergeResourceInclude Source="avares://Avalonia.Themes.Fluent/Controls/Button.xaml" /> |
|
|
|
<MergeResourceInclude Source="avares://Avalonia.Themes.Fluent/Controls/RadioButton.xaml" /> |
|
|
|
<MergeResourceInclude Source="avares://Avalonia.Themes.Fluent/Controls/Expander.xaml" /> |
|
|
|
@ -74,6 +75,5 @@ |
|
|
|
</ResourceDictionary> |
|
|
|
</Styles.Resources> |
|
|
|
|
|
|
|
<StyleInclude Source="avares://Avalonia.Themes.Fluent/Controls/FocusAdorner.xaml" /> |
|
|
|
<StyleInclude Source="avares://Avalonia.Themes.Fluent/Controls/UserControl.xaml" /> |
|
|
|
</Styles> |
|
|
|
|
|
|
|
@ -0,0 +1,13 @@ |
|
|
|
<ResourceDictionary xmlns="https://github.com/avaloniaui" |
|
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
|
|
|
<ControlTheme x:Key="{x:Type AdornerLayer}" TargetType="AdornerLayer"> |
|
|
|
<Setter Property="DefaultFocusAdorner"> |
|
|
|
<FocusAdornerTemplate> |
|
|
|
<Rectangle Margin="1" |
|
|
|
Stroke="Black" |
|
|
|
StrokeDashArray="1,2" |
|
|
|
StrokeThickness="1" /> |
|
|
|
</FocusAdornerTemplate> |
|
|
|
</Setter> |
|
|
|
</ControlTheme> |
|
|
|
</ResourceDictionary> |
|
|
|
@ -1,11 +0,0 @@ |
|
|
|
<Style xmlns="https://github.com/avaloniaui" |
|
|
|
Selector=":is(Control)"> |
|
|
|
<Setter Property="FocusAdorner"> |
|
|
|
<FocusAdornerTemplate> |
|
|
|
<Rectangle Margin="1" |
|
|
|
Stroke="Black" |
|
|
|
StrokeDashArray="1,2" |
|
|
|
StrokeThickness="1" /> |
|
|
|
</FocusAdornerTemplate> |
|
|
|
</Setter> |
|
|
|
</Style> |
|
|
|
@ -3,6 +3,7 @@ |
|
|
|
<Styles.Resources> |
|
|
|
<ResourceDictionary> |
|
|
|
<ResourceDictionary.MergedDictionaries> |
|
|
|
<MergeResourceInclude Source="avares://Avalonia.Themes.Simple/Controls/AdornerLayer.xaml" /> |
|
|
|
<MergeResourceInclude Source="avares://Avalonia.Themes.Simple/Controls/Button.xaml" /> |
|
|
|
<MergeResourceInclude Source="avares://Avalonia.Themes.Simple/Controls/RadioButton.xaml" /> |
|
|
|
<MergeResourceInclude Source="avares://Avalonia.Themes.Simple/Controls/Expander.xaml" /> |
|
|
|
@ -72,6 +73,5 @@ |
|
|
|
</ResourceDictionary> |
|
|
|
</Styles.Resources> |
|
|
|
|
|
|
|
<StyleInclude Source="avares://Avalonia.Themes.Simple/Controls/FocusAdorner.xaml" /> |
|
|
|
<StyleInclude Source="avares://Avalonia.Themes.Simple/Controls/UserControl.xaml" /> |
|
|
|
</Styles> |
|
|
|
|