feat: add checkbox border style

This commit is contained in:
rabbitism 2023-03-17 23:12:24 +08:00
parent 4b7920909c
commit f0d0ed918a
4 changed files with 269 additions and 15 deletions

View File

@ -7,18 +7,76 @@
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<StackPanel Spacing="20">
<CheckBox>Unchecked</CheckBox>
<CheckBox IsEnabled="False">Unchecked</CheckBox>
<CheckBox IsChecked="True">Checked</CheckBox>
<CheckBox IsChecked="True" IsEnabled="False">Checked</CheckBox>
<CheckBox IsChecked="{x:Null}" IsThreeState="True">Indeterminate</CheckBox>
<CheckBox
IsChecked="{x:Null}"
IsEnabled="False"
IsThreeState="True">
Indeterminate
</CheckBox>
<CheckBox Width="120">Checkbox should wrap its text</CheckBox>
</StackPanel>
<ScrollViewer>
<StackPanel HorizontalAlignment="Left">
<CheckBox>Unchecked</CheckBox>
<CheckBox IsEnabled="False">Unchecked</CheckBox>
<CheckBox IsChecked="True">Checked</CheckBox>
<CheckBox IsChecked="True" IsEnabled="False">Checked</CheckBox>
<CheckBox IsChecked="{x:Null}" IsThreeState="True">Indeterminate</CheckBox>
<CheckBox
IsChecked="{x:Null}"
IsEnabled="False"
IsThreeState="True">
Indeterminate
</CheckBox>
<CheckBox Width="120">Checkbox should wrap its text</CheckBox>
<CheckBox Width="300" Theme="{DynamicResource CardCheckBox}">
<StackPanel>
<TextBlock FontWeight="Bold">复选框标题</TextBlock>
<TextBlock TextWrapping="Wrap">Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统</TextBlock>
</StackPanel>
</CheckBox>
<CheckBox
Width="300"
IsChecked="True"
Theme="{DynamicResource CardCheckBox}">
<StackPanel>
<TextBlock FontWeight="Bold">复选框标题</TextBlock>
<TextBlock TextWrapping="Wrap">Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统</TextBlock>
</StackPanel>
</CheckBox>
<CheckBox
Width="300"
IsEnabled="False"
Theme="{DynamicResource CardCheckBox}">
<StackPanel>
<TextBlock FontWeight="Bold">复选框标题</TextBlock>
<TextBlock TextWrapping="Wrap">Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统</TextBlock>
</StackPanel>
</CheckBox>
<CheckBox
Width="300"
IsChecked="True"
IsEnabled="False"
Theme="{DynamicResource CardCheckBox}">
<StackPanel>
<TextBlock FontWeight="Bold">复选框标题</TextBlock>
<TextBlock TextWrapping="Wrap">Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统</TextBlock>
</StackPanel>
</CheckBox>
<CheckBox
Width="300"
IsChecked="{x:Null}"
IsEnabled="True"
IsThreeState="True"
Theme="{DynamicResource CardCheckBox}">
<StackPanel>
<TextBlock FontWeight="Bold">复选框标题</TextBlock>
<TextBlock TextWrapping="Wrap">Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统</TextBlock>
</StackPanel>
</CheckBox>
<CheckBox
Width="300"
IsChecked="{x:Null}"
IsEnabled="False"
IsThreeState="True"
Theme="{DynamicResource CardCheckBox}">
<StackPanel>
<TextBlock FontWeight="Bold">复选框标题</TextBlock>
<TextBlock TextWrapping="Wrap">Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统</TextBlock>
</StackPanel>
</CheckBox>
</StackPanel>
</ScrollViewer>
</UserControl>

View File

@ -4,8 +4,8 @@
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="Center" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="{DynamicResource CheckboxFontSize}" />
@ -21,6 +21,7 @@
x:Name="PART_Border"
Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Center"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
@ -175,4 +176,178 @@
</Style>
</Style>
</ControlTheme>
<ControlTheme x:Key="CardCheckBox" TargetType="CheckBox">
<Setter Property="Padding" Value="{DynamicResource CheckboxCardPadding}" />
<Setter Property="BorderThickness" Value="{DynamicResource CheckboxCardBorderThickness}" />
<Setter Property="CornerRadius" Value="{DynamicResource CheckboxCardCornerRadius}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="CheckBox.Template">
<ControlTemplate TargetType="CheckBox">
<Border
Name="RootBorder"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid x:Name="RootGrid" ColumnDefinitions="Auto,*">
<Grid Grid.Column="0" VerticalAlignment="Top">
<Border
x:Name="NormalRectangle"
Width="{DynamicResource CheckboxBoxWidth}"
Height="{DynamicResource CheckboxBoxHeight}"
Background="{DynamicResource CheckboxDefaultBackground}"
BorderBrush="{DynamicResource CheckboxDefaultBorderBrush}"
BorderThickness="{DynamicResource CheckboxBoxBorderThickness}"
CornerRadius="{DynamicResource CheckboxBoxCornerRadius}"
UseLayoutRounding="False" />
<PathIcon
Name="CheckGlyph"
Width="{DynamicResource CheckboxBoxGlyphWidth}"
Height="{DynamicResource CheckboxBoxGlyphHeight}"
Foreground="{DynamicResource CheckboxGlyphFill}" />
</Grid>
<ContentPresenter
x:Name="ContentPresenter"
Grid.Column="1"
Margin="8,0,0,0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
IsVisible="{TemplateBinding Content,
Converter={x:Static ObjectConverters.IsNotNull}}"
RecognizesAccessKey="True"
TextWrapping="Wrap" />
</Grid>
</Border>
</ControlTemplate>
</Setter>
<!-- Unchecked PointerOver State -->
<Style Selector="^:pointerover">
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxPointOverBorderBrush}" />
</Style>
<Style Selector="^ /template/ Border#RootBorder">
<Setter Property="Background" Value="{DynamicResource CheckboxCardPointeroverBackground}" />
</Style>
</Style>
<!-- Unchecked Pressed State -->
<Style Selector="^:pressed">
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxPressedBorderBrush}" />
</Style>
<Style Selector="^ /template/ Border#RootBorder">
<Setter Property="Background" Value="{DynamicResource CheckboxCardPressedBackground}" />
</Style>
</Style>
<!-- Unchecked Disabled state -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ ContentPresenter#ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource CheckboxDisabledForeground}" />
</Style>
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxDefaultDisabledBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxDefaultDisabledBackground}" />
</Style>
</Style>
<Style Selector="^:checked">
<Style Selector="^ /template/ Border#RootBorder">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCardCheckedBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCardCheckedBackground}" />
</Style>
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCheckedDefaultBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCheckedDefaultBackground}" />
</Style>
<Style Selector="^ /template/ PathIcon#CheckGlyph">
<Setter Property="Data" Value="{DynamicResource CheckBoxCheckGlyph}" />
<Setter Property="Opacity" Value="1" />
</Style>
<!-- Checked PointerOver State -->
<Style Selector="^:pointerover">
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCheckedPointOverBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCheckedPointOverBackground}" />
</Style>
</Style>
<!-- Checked Pressed State -->
<Style Selector="^:pressed">
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCheckedPressedBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCheckedPressedBackground}" />
</Style>
</Style>
<!-- Checked Disabled State -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ Border#RootBorder">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCardCheckedDisabledBorderBrush}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource CheckboxDisabledForeground}" />
</Style>
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCheckedDisabledBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCheckedDisabledBackground}" />
</Style>
<Style Selector="^ /template/ Path#CheckGlyph">
<Setter Property="Fill" Value="{DynamicResource CheckboxGlyphDisabledFill}" />
</Style>
</Style>
</Style>
<Style Selector="^:indeterminate">
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCheckedDefaultBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCheckedDefaultBackground}" />
</Style>
<Style Selector="^ /template/ PathIcon#CheckGlyph">
<Setter Property="Data" Value="{DynamicResource CheckBoxIndeterminateGlyph}" />
<Setter Property="Opacity" Value="1" />
</Style>
<!-- Checked PointerOver State -->
<Style Selector="^:pointerover">
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCheckedPointOverBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCheckedPointOverBackground}" />
</Style>
</Style>
<!-- Checked Pressed State -->
<Style Selector="^:pressed">
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCheckedPressedBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCheckedPressedBackground}" />
</Style>
</Style>
<!-- Checked Disabled State -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ ContentPresenter#ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource CheckboxDisabledForeground}" />
</Style>
<Style Selector="^ /template/ Border#NormalRectangle">
<Setter Property="BorderBrush" Value="{DynamicResource CheckboxCheckedDisabledBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource CheckboxCheckedDisabledBackground}" />
</Style>
<Style Selector="^ /template/ Path#CheckGlyph">
<Setter Property="Fill" Value="{DynamicResource CheckboxGlyphDisabledFill}" />
</Style>
</Style>
</Style>
</ControlTheme>
</ResourceDictionary>

View File

@ -40,4 +40,14 @@
<PathGeometry x:Key="CheckBoxCheckGlyph">M17.4111 7.30848C18.0692 7.81171 18.1947 8.75312 17.6915 9.41119L11.1915 17.9112C10.909 18.2806 10.4711 18.4981 10.0061 18.5C9.54105 18.5019 9.10143 18.288 8.81592 17.9209L5.31592 13.4209C4.80731 12.767 4.92512 11.8246 5.57904 11.316C6.23296 10.8074 7.17537 10.9252 7.68398 11.5791L9.98988 14.5438L15.3084 7.58884C15.8116 6.93077 16.7531 6.80525 17.4111 7.30848Z</PathGeometry>
<PathGeometry x:Key="CheckBoxIndeterminateGlyph">M5 12.5C5 11.6716 5.67157 11 6.5 11H17.5C18.3284 11 19 11.6716 19 12.5C19 13.3284 18.3284 14 17.5 14H6.5C5.67157 14 5 13.3284 5 12.5Z</PathGeometry>
<SolidColorBrush x:Key="CheckboxCardCheckedBackground" Opacity="0.2" Color="#FF54A9FF" />
<SolidColorBrush x:Key="CheckboxCardCheckedBorderBrush" Color="#FF54A9FF" />
<SolidColorBrush x:Key="CheckboxCardCheckedDisabledBorderBrush" Color="#FF135CB8" />
<SolidColorBrush x:Key="CheckboxCardPointeroverBackground" Opacity="0.05" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="CheckboxCardPressedBackground" Opacity="0.09" Color="#FFFFFFFF" />
<Thickness x:Key="CheckboxCardBorderThickness">1</Thickness>
<Thickness x:Key="CheckboxCardPadding">16</Thickness>
<CornerRadius x:Key="CheckboxCardCornerRadius">3</CornerRadius>
</ResourceDictionary>

View File

@ -40,4 +40,15 @@
<PathGeometry x:Key="CheckBoxCheckGlyph">M17.4111 7.30848C18.0692 7.81171 18.1947 8.75312 17.6915 9.41119L11.1915 17.9112C10.909 18.2806 10.4711 18.4981 10.0061 18.5C9.54105 18.5019 9.10143 18.288 8.81592 17.9209L5.31592 13.4209C4.80731 12.767 4.92512 11.8246 5.57904 11.316C6.23296 10.8074 7.17537 10.9252 7.68398 11.5791L9.98988 14.5438L15.3084 7.58884C15.8116 6.93077 16.7531 6.80525 17.4111 7.30848Z</PathGeometry>
<PathGeometry x:Key="CheckBoxIndeterminateGlyph">M5 12.5C5 11.6716 5.67157 11 6.5 11H17.5C18.3284 11 19 11.6716 19 12.5C19 13.3284 18.3284 14 17.5 14H6.5C5.67157 14 5 13.3284 5 12.5Z</PathGeometry>
<SolidColorBrush x:Key="CheckboxCardCheckedBackground" Color="#FFEAF5FF" />
<SolidColorBrush x:Key="CheckboxCardCheckedBorderBrush" Color="#FF0077FA" />
<SolidColorBrush x:Key="CheckboxCardCheckedDisabledBorderBrush" Color="#FF98CDFD" />
<SolidColorBrush x:Key="CheckboxCardPointeroverBackground" Opacity="0.05" Color="#FF2E3238" />
<SolidColorBrush x:Key="CheckboxCardPressedBackground" Opacity="0.09" Color="#FF2E3238" />
<Thickness x:Key="CheckboxCardBorderThickness">1</Thickness>
<Thickness x:Key="CheckboxCardPadding">16</Thickness>
<CornerRadius x:Key="CheckboxCardCornerRadius">3</CornerRadius>
</ResourceDictionary>