具有圆角的WPF CheckBox

时间:2012-09-24 13:12:54

标签: wpf checkbox

是否可以通过修改自定义样式为WPF复选框设置圆角?如果是这样,这是怎么做到的?

2 个答案:

答案 0 :(得分:2)

是。它可能。

如果查看here,您可以获得现有复选框的完整样式,并且看起来边框不是由装饰器绘制的。所以只需改变你的风格并应用它。

<Border x:Name="Border"
                Width="13"
                Height="13"
 <!--Here-->        CornerRadius="0"
                BorderThickness="1">
          <Border.BorderBrush>

答案 1 :(得分:1)

我知道的最佳方式

<CheckBox Content="CheckBox" HorizontalAlignment="Left" Height="20" Margin="134,143,0,0" VerticalAlignment="Top" Width="176" Style="{DynamicResource CheckBoxStyle1}"/>

资源管理

<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>