Files
Shrlalgo.RvKits/WPFluent/Controls/RadioButton/RadioButton.xaml
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

213 lines
14 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<system:Double x:Key="RadioButtonCheckGlyphSize">12</system:Double>
<system:Double x:Key="RadioButtonOuterEllipseSize">20</system:Double>
<!--
<system:Double x:Key="RadioButtonCheckGlyphPointerOverSize">14</system:Double>
<system:Double x:Key="RadioButtonCheckGlyphPressedOverSize">10</system:Double>-->
<system:Double x:Key="RadioButtonStrokeThickness">1</system:Double>
<Thickness x:Key="RadioButtonPadding">8,6,0,0</Thickness>
<Style TargetType="{x:Type RadioButton}" x:Key="DefaultRadioButtonStyle">
<!-- Universal WPF UI focus -->
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<!-- Universal WPF UI focus -->
<Setter Property="Background" Value="{DynamicResource SystemFillColorAttentionBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Margin" Value="4,0" />
<Setter Property="Padding" Value="{StaticResource RadioButtonPadding}" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="KeyboardNavigation.IsTabStop" Value="True" />
<Setter Property="Focusable" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid
Background="Transparent"
HorizontalAlignment="Stretch"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Height="32" VerticalAlignment="Top">
<Ellipse
Fill="{DynamicResource ControlAltFillColorSecondaryBrush}"
Height="{StaticResource RadioButtonOuterEllipseSize}"
Stroke="{DynamicResource ControlStrongStrokeColorDefaultBrush}"
StrokeThickness="{StaticResource RadioButtonStrokeThickness}"
UseLayoutRounding="False"
Width="{StaticResource RadioButtonOuterEllipseSize}"
x:Name="OuterEllipse" />
<!-- A separate element is added since the two orthogonal state groups that cannot touch the same property -->
<Ellipse
Fill="{TemplateBinding Background}"
Height="{StaticResource RadioButtonOuterEllipseSize}"
Opacity="0"
Stroke="{TemplateBinding Background}"
StrokeThickness="{StaticResource RadioButtonStrokeThickness}"
UseLayoutRounding="False"
Width="{StaticResource RadioButtonOuterEllipseSize}"
x:Name="CheckOuterEllipse" />
<Ellipse
Fill="{DynamicResource TextOnAccentFillColorPrimaryBrush}"
Height="{StaticResource RadioButtonCheckGlyphSize}"
Opacity="0"
Stroke="{DynamicResource CircleElevationBorderBrush}"
UseLayoutRounding="False"
Width="{StaticResource RadioButtonCheckGlyphSize}"
x:Name="CheckGlyph">
<Ellipse.LayoutTransform>
<ScaleTransform ScaleX="1.0" ScaleY="1.0" />
</Ellipse.LayoutTransform>
</Ellipse>
<!-- A separate element is added since the two orthogonal state groups that cannot touch the same property -->
<Border
Background="{DynamicResource TextOnAccentFillColorPrimaryBrush}"
BorderBrush="{DynamicResource CircleElevationBorderBrush}"
CornerRadius="6"
Height="4"
Opacity="0"
UseLayoutRounding="False"
Width="4"
x:Name="PressedCheckGlyph" />
</Grid>
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Grid.Column="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="ContentPresenter" />
</Grid>
<ControlTemplate.Triggers>
<!-- Clunky, todo
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsChecked" Value="True" />
<Condition Property="IsEnabled" Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="CheckGlyph"
Storyboard.TargetProperty="(Ellipse.LayoutTransform).(ScaleTransform.ScaleY)"
From="1.0"
To="1.2"
Duration="00:00:00.167" />
<DoubleAnimation
Storyboard.TargetName="CheckGlyph"
Storyboard.TargetProperty="(Ellipse.LayoutTransform).(ScaleTransform.ScaleX)"
From="1.0"
To="1.2"
Duration="00:00:00.167" />
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="CheckGlyph"
Storyboard.TargetProperty="(Ellipse.LayoutTransform).(ScaleTransform.ScaleY)"
From="1.2"
To="1.0"
Duration="00:00:00.167" />
<DoubleAnimation
Storyboard.TargetName="CheckGlyph"
Storyboard.TargetProperty="(Ellipse.LayoutTransform).(ScaleTransform.ScaleX)"
From="1.2"
To="1.0"
Duration="00:00:00.167" />
</Storyboard>
</BeginStoryboard>
</MultiTrigger.ExitActions>
</MultiTrigger>
-->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsPressed" Value="True" />
<Condition Property="IsChecked" Value="False" />
<Condition Property="IsEnabled" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Opacity" TargetName="CheckGlyph" Value="1.0" />
<Setter Property="Fill" TargetName="OuterEllipse" Value="{DynamicResource ControlAltFillColorQuarternaryBrush}" />
<Setter Property="Stroke" TargetName="OuterEllipse" Value="{DynamicResource ControlStrongStrokeColorDisabledBrush}" />
</MultiTrigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Opacity" TargetName="CheckGlyph" Value="1.0" />
<Setter Property="Opacity" TargetName="OuterEllipse" Value="0.0" />
<Setter Property="Opacity" TargetName="CheckOuterEllipse" Value="1.0" />
</Trigger>
<Trigger Property="FlowDirection" Value="RightToLeft">
<Setter Property="HorizontalAlignment" Value="Right" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsChecked" Value="False" />
<Condition Property="IsEnabled" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Fill" TargetName="OuterEllipse" Value="{DynamicResource ControlAltFillColorTertiaryBrush}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsChecked" Value="True" />
<Condition Property="IsEnabled" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Fill" TargetName="OuterEllipse" Value="{DynamicResource ControlAltFillColorTertiaryBrush}" />
<!--<Setter TargetName="CheckGlyph" Property="Fill" Value="{DynamicResource SystemFillColorAttentionBrush}" />-->
<Setter Property="Background" TargetName="PressedCheckGlyph" Value="{DynamicResource SystemFillColorAttentionBrush}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsChecked" Value="False" />
<Condition Property="IsEnabled" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="Fill" TargetName="OuterEllipse" Value="{DynamicResource ControlAltFillColorDisabledBrush}" />
<Setter Property="Stroke" TargetName="OuterEllipse" Value="{DynamicResource ControlStrongStrokeColorDisabledBrush}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsChecked" Value="True" />
<Condition Property="IsEnabled" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="Fill" TargetName="OuterEllipse" Value="{DynamicResource ControlAltFillColorDisabledBrush}" />
<Setter Property="Stroke" TargetName="OuterEllipse" Value="{DynamicResource RadioButtonOuterEllipseCheckedStrokeDisabled}" />
<Setter Property="Opacity" TargetName="CheckGlyph" Value="0.7" />
<Setter Property="Opacity" TargetName="CheckOuterEllipse" Value="0.7" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource DefaultRadioButtonStyle}" TargetType="{x:Type RadioButton}" />
</ResourceDictionary>