Reputation: 1453
Is it possible to style a WPF checkbox to have rounded corners by modifying a custom style? If so, how is this done?
Upvotes: 1
Views: 10740
Reputation: 4215
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>
Upvotes: 2
Reputation: 6961
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>
Upvotes: 2