Checkbox 模板和样式

     <Style TargetType="{x:Type CheckBox}">
<Setter Property="FontFamily" Value="Microsoft YaHei" />
<Setter Property="FontSize" Value="12" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Background" Value="{DynamicResource ButtonBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorder}" />
<Setter Property="Foreground" Value="{DynamicResource WindowText}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Grid x:Name="LayoutRoot" Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border x:Name="CheckBorder" Width="16" Height="16" Margin="0,1,4,0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Path x:Name="CheckMark"
Width="10" Height="10"
Margin="2"
Data="F1M15,21L22,28 32.9999,14.0001 35.9999,17.0001 22,34 12.0001,24 15,21z"
Fill="{TemplateBinding Foreground}"
Stretch="Fill" Visibility="Collapsed" />
<Rectangle x:Name="Indeterminate" Width="8" Height="8" Margin="4" Fill="{TemplateBinding Foreground}" Visibility="Hidden" />
</Grid>
</Border>
<ContentPresenter Grid.Column="1"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Focusable="False" RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
<ControlTemplate.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsThreeState, RelativeSource={RelativeSource Self}}" Value="True" />
<Condition Binding="{Binding IsChecked, RelativeSource={RelativeSource Self}}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}" />
<Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed" />
<Setter TargetName="Indeterminate" Property="Visibility" Value="Visible" />
</MultiDataTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
<Setter TargetName="Indeterminate" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="CheckBorder" Property="Background" Value="{DynamicResource ButtonBackgroundHover}" />
<Setter TargetName="CheckBorder" Property="BorderBrush" Value="{DynamicResource ButtonBorderHover}" />
<Setter TargetName="CheckMark" Property="Fill" Value="{DynamicResource ButtonTextHover}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="CheckBorder" Property="Background" Value="{DynamicResource ButtonBackgroundPressed}" />
<Setter TargetName="CheckBorder" Property="BorderBrush" Value="{DynamicResource ButtonBorderPressed}" />
<Setter TargetName="CheckMark" Property="Fill" Value="{DynamicResource ButtonTextPressed}" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="CheckBorder" Property="BorderBrush" Value="{DynamicResource Accent}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

应用

 <CheckBox Content="checkbox"/>

Checkbox 模板和样式

引用:

https://msdn.microsoft.com/zh-cn/library/ms752319(v=vs.110).aspx

一些疑点将会在后期补充

上一篇:MahApps.Metro使用


下一篇:Button 模板和样式