feat: unity default theme of CheckBox & RadioButton.

This commit is contained in:
Zhang Dian 2024-09-21 22:12:00 +08:00
parent d42c8cce78
commit ae1f4ffe60
4 changed files with 38 additions and 57 deletions

View File

@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:CompileBindings="True">
<ControlTheme x:Key="{x:Type CheckBox}" TargetType="CheckBox">
<Setter Property="Padding" Value="8,0,0,0" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Cursor" Value="Hand" />
@ -11,7 +10,6 @@
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="{DynamicResource CheckBoxFontSize}" />
<Setter Property="CornerRadius" Value="{DynamicResource CheckBoxBoxCornerRadius}" />
<Setter Property="MinHeight" Value="32" />
<Setter Property="Foreground" Value="{DynamicResource CheckBoxForeground}" />
<Setter Property="Background" Value="{DynamicResource CheckBoxDefaultBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource CheckBoxDefaultBorderBrush}" />
@ -23,12 +21,11 @@
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid x:Name="RootGrid" ColumnDefinitions="Auto,*">
<Grid
<Grid ColumnDefinitions="Auto,*">
<Panel
Grid.Column="0"
TemplatedControl.IsTemplateFocusTarget="True"
Margin="0,0,0,0"
VerticalAlignment="Center">
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Border
x:Name="NormalRectangle"
Width="{DynamicResource CheckBoxBoxWidth}"
@ -39,21 +36,22 @@
CornerRadius="{TemplateBinding CornerRadius}"
UseLayoutRounding="False" />
<PathIcon
Name="CheckGlyph"
x:Name="CheckGlyph"
Width="{DynamicResource CheckBoxBoxGlyphWidth}"
Height="{DynamicResource CheckBoxBoxGlyphHeight}"
Foreground="{DynamicResource CheckBoxGlyphFill}" />
</Grid>
</Panel>
<ContentPresenter
x:Name="ContentPresenter"
x:Name="PART_ContentPresenter"
Grid.Column="1"
Margin="{TemplateBinding Padding}"
Margin="{DynamicResource CheckBoxContentMargin}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
IsVisible="{TemplateBinding Content,Converter={x:Static ObjectConverters.IsNotNull}}"
RecognizesAccessKey="True"
FontSize="{TemplateBinding FontSize}"
TextWrapping="Wrap" />
</Grid>
</Border>
@ -78,7 +76,7 @@
<!-- Unchecked Disabled state -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ ContentPresenter#ContentPresenter">
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource CheckBoxDisabledForeground}" />
</Style>
<Style Selector="^ /template/ Border#NormalRectangle">
@ -116,7 +114,7 @@
<!-- Checked Disabled State -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ ContentPresenter#ContentPresenter">
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource CheckBoxDisabledForeground}" />
</Style>
<Style Selector="^ /template/ Border#NormalRectangle">
@ -159,7 +157,7 @@
<!-- Checked Disabled State -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ ContentPresenter#ContentPresenter">
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource CheckBoxDisabledForeground}" />
</Style>
<Style Selector="^ /template/ Border#NormalRectangle">

View File

@ -18,63 +18,59 @@
</Design.PreviewWith>
<!-- Theme: Default, Button, Card, PureCard -->
<ControlTheme x:Key="{x:Type RadioButton}" TargetType="RadioButton">
<Setter Property="RadioButton.HorizontalAlignment" Value="Left" />
<Setter Property="RadioButton.VerticalAlignment" Value="Top" />
<Setter Property="RadioButton.Cursor" Value="Hand" />
<Setter Property="RadioButton.HorizontalContentAlignment" Value="Left" />
<Setter Property="RadioButton.VerticalContentAlignment" Value="Center" />
<Setter Property="RadioButton.FontSize" Value="{DynamicResource RadioButtonFontSize}" />
<Setter Property="RadioButton.CornerRadius" Value="{DynamicResource RadioButtonBoxCornerRadius}" />
<Setter Property="RadioButton.Foreground" Value="{DynamicResource RadioButtonForeground}" />
<Setter Property="RadioButton.Background" Value="{DynamicResource RadioButtonDefaultBackground}" />
<Setter Property="RadioButton.BorderBrush" Value="{DynamicResource RadioButtonDefaultBorderBrush}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="{DynamicResource RadioButtonFontSize}" />
<Setter Property="CornerRadius" Value="{DynamicResource RadioButtonBoxCornerRadius}" />
<Setter Property="Foreground" Value="{DynamicResource RadioButtonForeground}" />
<Setter Property="Background" Value="{DynamicResource RadioButtonDefaultBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource RadioButtonDefaultBorderBrush}" />
<Setter Property="Template">
<ControlTemplate TargetType="RadioButton">
<Border
Name="RootBorder"
Margin="{TemplateBinding Margin}"
Padding="{TemplateBinding Padding}"
x:Name="RootBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid ColumnDefinitions="Auto,*">
<Grid
<Panel
Grid.Column="0"
TemplatedControl.IsTemplateFocusTarget="True"
Margin="{DynamicResource RadioButtonIconMargin}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Ellipse
Name="OuterEllipse"
x:Name="OuterEllipse"
Width="{DynamicResource RadioButtonIconRadius}"
Height="{DynamicResource RadioButtonIconRadius}"
Fill="{DynamicResource RadioButtonUncheckIconDefaultBackground}"
Stroke="{DynamicResource RadioButtonUncheckIconDefaultBorderBrush}"
StrokeThickness="1"
StrokeThickness="{DynamicResource RadioButtonUncheckIconDefaultThickness}"
UseLayoutRounding="False" />
<Ellipse
Name="CheckGlyph"
x:Name="CheckGlyph"
Width="{DynamicResource RadioButtonGlyphRadius}"
Height="{DynamicResource RadioButtonGlyphRadius}"
Fill="{DynamicResource RadioButtonCheckGlyphFill}"
Opacity="0"
Stroke="{DynamicResource RadioButtonCheckGlyphFill}"
StrokeThickness="0"
UseLayoutRounding="False" />
</Grid>
</Panel>
<ContentPresenter
Name="PART_ContentPresenter"
x:Name="PART_ContentPresenter"
Grid.Column="1"
Margin="{DynamicResource RadioButtonContentMargin}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Foreground="{TemplateBinding Foreground}"
IsVisible="{TemplateBinding Content,Converter={x:Static ObjectConverters.IsNotNull}}"
RecognizesAccessKey="True"
TextElement.FontSize="{DynamicResource RadioButtonFontSize}"
TextElement.Foreground="{DynamicResource RadioButtonForeground}" />
FontSize="{TemplateBinding FontSize}"
TextWrapping="Wrap" />
</Grid>
</Border>
</ControlTemplate>
@ -96,9 +92,6 @@
<Setter Property="Stroke" Value="{DynamicResource RadioButtonUncheckIconPointeroverBorderBrush}" />
<Setter Property="Fill" Value="{DynamicResource RadioButtonUncheckIconPointeroverBackground}" />
</Style>
<Style Selector="^ /template/ Ellipse#CheckGlyph">
<Setter Property="Opacity" Value="0" />
</Style>
</Style>
<!-- Unchecked Pressed State -->
@ -107,9 +100,6 @@
<Setter Property="Stroke" Value="{DynamicResource RadioButtonUncheckIconPressedBorderBrush}" />
<Setter Property="Fill" Value="{DynamicResource RadioButtonUncheckIconPressedBackground}" />
</Style>
<Style Selector="^ /template/ Ellipse#CheckGlyph">
<Setter Property="Opacity" Value="0" />
</Style>
</Style>
<!-- Unchecked Disabled state -->
@ -118,9 +108,6 @@
<Setter Property="Stroke" Value="{DynamicResource RadioButtonUncheckIconDisabledBorderBrush}" />
<Setter Property="Fill" Value="{DynamicResource RadioButtonUncheckIconDisabledBackground}" />
</Style>
<Style Selector="^ /template/ Ellipse#CheckGlyph">
<Setter Property="Opacity" Value="0" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource RadioButtonDisabledForeground}" />
</Style>
@ -143,9 +130,6 @@
<Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckIconPointeroverBorderBrush}" />
<Setter Property="Fill" Value="{DynamicResource RadioButtonCheckIconPointeroverBackground}" />
</Style>
<Style Selector="^ /template/ Ellipse#CheckGlyph">
<Setter Property="Opacity" Value="1" />
</Style>
</Style>
<!-- Checked Pressed State -->
@ -154,9 +138,6 @@
<Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckIconPressedBorderBrush}" />
<Setter Property="Fill" Value="{DynamicResource RadioButtonCheckIconPressedBackground}" />
</Style>
<Style Selector="^ /template/ Ellipse#CheckGlyph">
<Setter Property="Opacity" Value="1" />
</Style>
</Style>
<!-- Checked Disabled State -->
@ -165,9 +146,6 @@
<Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckIconDisabledBorderBrush}" />
<Setter Property="Fill" Value="{DynamicResource RadioButtonCheckIconDisabledBackground}" />
</Style>
<Style Selector="^ /template/ Ellipse#CheckGlyph">
<Setter Property="Opacity" Value="1" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource RadioButtonDisabledForeground}" />
</Style>

View File

@ -2,6 +2,8 @@
<x:Double x:Key="CheckBoxFontSize">14</x:Double>
<x:Double x:Key="CheckBoxBoxWidth">16</x:Double>
<x:Double x:Key="CheckBoxBoxHeight">16</x:Double>
<Thickness x:Key="CheckBoxContentMargin">8 0 0 0</Thickness>
<x:Double x:Key="CheckBoxBoxGlyphWidth">10</x:Double>
<x:Double x:Key="CheckBoxBoxGlyphHeight">10</x:Double>

View File

@ -5,6 +5,9 @@
<x:Double x:Key="RadioButtonFontSize">14</x:Double>
<Thickness x:Key="RadioButtonIconMargin">0 2 8 0</Thickness>
<x:Double x:Key="RadioButtonUncheckIconDefaultThickness">1</x:Double>
<Thickness x:Key="RadioButtonContentMargin">8 0 0 0</Thickness>
<!-- ButtonRadioButton -->
<CornerRadius x:Key="RadioButtonBoxCornerRadius">3</CornerRadius>