Merge pull request #405 from irihitech/adorner

Update AdornerLayer
This commit is contained in:
Dong Bin 2024-08-08 16:17:14 +08:00 committed by GitHub
commit 1b5a5d5ea1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 110 additions and 104 deletions

View File

@ -5,11 +5,8 @@
<ControlTheme x:Key="{x:Type AdornerLayer}" TargetType="AdornerLayer"> <ControlTheme x:Key="{x:Type AdornerLayer}" TargetType="AdornerLayer">
<Setter Property="DefaultFocusAdorner"> <Setter Property="DefaultFocusAdorner">
<FocusAdornerTemplate> <FocusAdornerTemplate>
<Rectangle <Border BorderThickness="{DynamicResource AdornerLayerBorderThickness}"
Margin="{DynamicResource AdornerLayerMargin}" BorderBrush="{DynamicResource AdornerLayerStroke}" />
Stroke="{DynamicResource AdornerLayerBackground}"
StrokeDashArray="1,2"
StrokeThickness="{DynamicResource AdornerLayerThickness}" />
</FocusAdornerTemplate> </FocusAdornerTemplate>
</Setter> </Setter>
</ControlTheme> </ControlTheme>

View File

@ -26,6 +26,7 @@
<Grid x:Name="RootGrid" ColumnDefinitions="Auto,*"> <Grid x:Name="RootGrid" ColumnDefinitions="Auto,*">
<Grid <Grid
Grid.Column="0" Grid.Column="0"
TemplatedControl.IsTemplateFocusTarget="True"
Margin="0,0,0,0" Margin="0,0,0,0"
VerticalAlignment="Center"> VerticalAlignment="Center">
<Border <Border

View File

@ -39,7 +39,11 @@
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"> CornerRadius="{TemplateBinding CornerRadius}">
<Grid ColumnDefinitions="Auto,*"> <Grid ColumnDefinitions="Auto,*">
<Grid Margin="{DynamicResource RadioButtonIconMargin}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> <Grid
Grid.Column="0"
TemplatedControl.IsTemplateFocusTarget="True"
Margin="{DynamicResource RadioButtonIconMargin}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Ellipse <Ellipse
Name="OuterEllipse" Name="OuterEllipse"
Width="{DynamicResource RadioButtonIconRadius}" Width="{DynamicResource RadioButtonIconRadius}"

View File

@ -15,6 +15,13 @@
<Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FocusAdorner">
<FocusAdornerTemplate>
<Border BorderThickness="{DynamicResource AdornerLayerBorderThickness}"
BorderBrush="{DynamicResource AdornerLayerStroke}"
CornerRadius="100"/>
</FocusAdornerTemplate>
</Setter>
<Setter Property="KnobTransitions"> <Setter Property="KnobTransitions">
<Transitions> <Transitions>
<DoubleTransition <DoubleTransition
@ -28,107 +35,99 @@
<Grid <Grid
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
Cursor="Hand" Cursor="Hand"
RowDefinitions="Auto,*"> RowDefinitions="Auto,*"
ColumnDefinitions="Auto, *">
<ContentPresenter <ContentPresenter
x:Name="PART_ContentPresenter" x:Name="PART_ContentPresenter"
Grid.Row="0" Grid.Row="0" Grid.Column="0"
Grid.ColumnSpan="2"
Margin="{DynamicResource ToggleSwitchHeaderMargin}" Margin="{DynamicResource ToggleSwitchHeaderMargin}"
VerticalAlignment="Top" VerticalAlignment="Top"
Content="{TemplateBinding Content}" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplate="{TemplateBinding ContentTemplate}"
IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNotNull}}" IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNotNull}}"
RecognizesAccessKey="True" /> RecognizesAccessKey="True" />
<Grid
Grid.Row="1" <Border
Background="Transparent" x:Name="SwitchBackgroundBorder"
ColumnDefinitions="Auto, *"> Grid.Row="1" Grid.Column="0"
<Grid TemplatedControl.IsTemplateFocusTarget="True"
Grid.Column="0" Width="{DynamicResource ToggleSwitchDefaultWidth}"
Grid.ColumnSpan="2" Height="{DynamicResource ToggleSwitchDefaultHeight}"
TemplatedControl.IsTemplateFocusTarget="True" /> CornerRadius="100">
<Border <Border.Transitions>
x:Name="SwitchBackgroundBorder" <Transitions>
Grid.Column="0" <BrushTransition Property="Background" Duration="0:0:0.2" />
Width="{DynamicResource ToggleSwitchDefaultWidth}" </Transitions>
Height="{DynamicResource ToggleSwitchDefaultHeight}" </Border.Transitions>
CornerRadius="100"> <Canvas
<Border.Transitions> x:Name="PART_SwitchKnob"
<Transitions> Width="{DynamicResource ToggleSwitchIndicatorDefaultWidth}"
<BrushTransition Property="Background" Duration="0:0:0.2" /> Height="{DynamicResource ToggleSwitchIndicatorDefaultWidth}"
</Transitions> HorizontalAlignment="Left">
</Border.Transitions> <Grid
<Canvas x:Name="PART_MovingKnobs"
x:Name="PART_SwitchKnob"
Width="{DynamicResource ToggleSwitchIndicatorDefaultWidth}" Width="{DynamicResource ToggleSwitchIndicatorDefaultWidth}"
Height="{DynamicResource ToggleSwitchIndicatorDefaultWidth}" Height="{DynamicResource ToggleSwitchIndicatorDefaultWidth}"
HorizontalAlignment="Left"> Margin="{DynamicResource ToggleSwitchIndicatorDefaultMargin}">
<Grid <Border
x:Name="PART_MovingKnobs" x:Name="SwitchKnobIndicator"
Width="{DynamicResource ToggleSwitchIndicatorDefaultWidth}" Background="White"
Height="{DynamicResource ToggleSwitchIndicatorDefaultWidth}" BoxShadow="0 0 1 1 #222E3238"
Margin="{DynamicResource ToggleSwitchIndicatorDefaultMargin}"> CornerRadius="100" />
<Border <Arc
x:Name="SwitchKnobIndicator" x:Name="SwitchKnobLoadingIndicator"
Background="White" IsVisible="False"
BoxShadow="0 0 1 1 #222E3238" StrokeThickness="2"
CornerRadius="100" /> StartAngle="0"
<Arc SweepAngle="140"
x:Name="SwitchKnobLoadingIndicator" StrokeJoin="Round"
IsVisible="False" StrokeLineCap="Round">
StrokeThickness="2" <Arc.Stroke>
StartAngle="0" <ConicGradientBrush>
SweepAngle="140" <GradientStops>
StrokeJoin="Round" <GradientStop Offset="0.1" Color="Transparent" />
StrokeLineCap="Round"> <GradientStop Offset="0.7" Color="White" />
<Arc.Stroke> </GradientStops>
<ConicGradientBrush> </ConicGradientBrush>
<GradientStops> </Arc.Stroke>
<GradientStop Offset="0.1" Color="Transparent"/> <Arc.Styles>
<GradientStop Offset="0.7" Color="White"/> <Style Selector="Arc[IsVisible=True]">
</GradientStops> <Style.Animations>
</ConicGradientBrush> <Animation IterationCount="Infinite" Duration="0:0:0.6">
</Arc.Stroke> <KeyFrame Cue="0%">
<Arc.Styles> <Setter Property="RotateTransform.Angle" Value="0.0" />
<Style Selector="Arc[IsVisible=True]"> </KeyFrame>
<Style.Animations> <KeyFrame Cue="100%">
<Animation IterationCount="Infinite" Duration="0:0:0.6"> <Setter Property="RotateTransform.Angle" Value="360.0" />
<KeyFrame Cue="0%"> </KeyFrame>
<Setter Property="RotateTransform.Angle" Value="0.0" /> </Animation>
</KeyFrame> </Style.Animations>
<KeyFrame Cue="100%"> </Style>
<Setter Property="RotateTransform.Angle" Value="360.0" /> </Arc.Styles>
</KeyFrame> </Arc>
</Animation> </Grid>
</Style.Animations> </Canvas>
</Style> </Border>
</Arc.Styles>
</Arc>
</Grid>
</Canvas>
</Border>
<ContentPresenter <ContentPresenter
x:Name="PART_OnContentPresenter" x:Name="PART_OnContentPresenter"
Grid.Column="1" Grid.Row="1" Grid.Column="1"
Margin="{DynamicResource ToggleSwitchOnContentMargin}" Margin="{DynamicResource ToggleSwitchOnContentMargin}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Center" VerticalAlignment="Center"
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
Content="{TemplateBinding OnContent}" Content="{TemplateBinding OnContent}"
ContentTemplate="{TemplateBinding OnContentTemplate}" ContentTemplate="{TemplateBinding OnContentTemplate}" />
IsVisible="True" /> <ContentPresenter
<ContentPresenter x:Name="PART_OffContentPresenter"
x:Name="PART_OffContentPresenter" Grid.Row="1" Grid.Column="1"
Grid.Column="1" Margin="{DynamicResource ToggleSwitchOnContentMargin}"
Margin="{DynamicResource ToggleSwitchOnContentMargin}" HorizontalAlignment="Left"
HorizontalAlignment="Left" VerticalAlignment="Center"
VerticalAlignment="Center" VerticalContentAlignment="Center"
VerticalContentAlignment="Center" Content="{TemplateBinding OffContent}"
Content="{TemplateBinding OffContent}" ContentTemplate="{TemplateBinding OffContentTemplate}" />
ContentTemplate="{TemplateBinding OffContentTemplate}"
IsVisible="False" />
</Grid>
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
@ -241,6 +240,12 @@
<Setter Property="Padding" Value="8" /> <Setter Property="Padding" Value="8" />
<Setter Property="CornerRadius" Value="3" /> <Setter Property="CornerRadius" Value="3" />
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
<Setter Property="FocusAdorner">
<FocusAdornerTemplate>
<Border BorderThickness="{DynamicResource AdornerLayerBorderThickness}"
BorderBrush="{DynamicResource AdornerLayerStroke}" />
</FocusAdornerTemplate>
</Setter>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="ToggleSwitch"> <ControlTemplate TargetType="ToggleSwitch">
<Border <Border
@ -249,9 +254,9 @@
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}" CornerRadius="{TemplateBinding CornerRadius}"
Cursor="Hand"> Cursor="Hand">
<Grid ColumnDefinitions="Auto"> <Panel>
<Grid x:Name="PART_SwitchKnob" /> <Panel x:Name="PART_SwitchKnob" />
<Grid x:Name="PART_MovingKnobs" /> <Panel x:Name="PART_MovingKnobs" />
<ContentPresenter <ContentPresenter
x:Name="PART_OnContentPresenter" x:Name="PART_OnContentPresenter"
Margin="{DynamicResource ToggleSwitchOnContentMargin}" Margin="{DynamicResource ToggleSwitchOnContentMargin}"
@ -262,7 +267,7 @@
Margin="{DynamicResource ToggleSwitchOnContentMargin}" Margin="{DynamicResource ToggleSwitchOnContentMargin}"
Content="{TemplateBinding OffContent}" Content="{TemplateBinding OffContent}"
ContentTemplate="{TemplateBinding OffContentTemplate}" /> ContentTemplate="{TemplateBinding OffContentTemplate}" />
</Grid> </Panel>
</Border> </Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>

View File

@ -1,3 +1,3 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="AdornerLayerBackground" Color="White" /> <SolidColorBrush x:Key="AdornerLayerStroke" Opacity="0.4" Color="#54A9FF" />
</ResourceDictionary> </ResourceDictionary>

View File

@ -1,3 +1,3 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="AdornerLayerBackground" Color="#1C1F23" /> <SolidColorBrush x:Key="AdornerLayerStroke" Color="#98CDFD" />
</ResourceDictionary> </ResourceDictionary>

View File

@ -1,4 +1,3 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Thickness x:Key="AdornerLayerMargin">1</Thickness> <Thickness x:Key="AdornerLayerBorderThickness">2</Thickness>
<x:Double x:Key="AdornerLayerThickness">1</x:Double>
</ResourceDictionary> </ResourceDictionary>