带圆角的 WPF 复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12565795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF CheckBox with Rounded Corners
提问by binncheol
Is it possible to style a WPF checkbox to have rounded corners by modifying a custom style? If so, how is this done?
是否可以通过修改自定义样式来为 WPF 复选框设置圆角样式?如果是这样,这是如何完成的?
回答by AlSki
Yes. Its possible.
是的。这是可能的。
If you look here, you can get the full style for an existing checkBox, and it appears that the Border isn't drawn by a Decorator. So just change this section in your style and apply it.
如果你看这里,你可以获得现有复选框的完整样式,看起来边框不是由装饰器绘制的。因此,只需按照您的风格更改此部分并应用即可。
<Border x:Name="Border"
Width="13"
Height="13"
<!--Here--> CornerRadius="0"
BorderThickness="1">
<Border.BorderBrush>
回答by Afshin
Best way that I know
我所知道的最好方法
<CheckBox Content="CheckBox" HorizontalAlignment="Left" Height="20" Margin="134,143,0,0" VerticalAlignment="Top" Width="176" Style="{DynamicResource CheckBoxStyle1}"/>
resource dictioanry
资源词典
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
<Style x:Key="CheckBoxStyle1" TargetType="{x:Type CheckBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<BulletDecorator Background="Transparent" SnapsToDevicePixels="true">
<BulletDecorator.Bullet>
<Border Background="#FFAEB3B9" BorderThickness="2" CornerRadius="10">
<Microsoft_Windows_Themes:BulletChrome IsChecked="{TemplateBinding IsChecked}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}"/>
</Border>
</BulletDecorator.Bullet>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</BulletDecorator>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

