带有圆角的 WPF 复选框



是否可以通过修改自定义样式来设置 WPF 复选框的样式以具有圆角?如果是这样,这是如何完成的?

我知道的最好的方式

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

是的。这是可能的。

如果您查看此处,则可以获取现有复选框的完整样式,并且边框似乎不是由装饰器绘制的。因此,只需按照您的样式更改此部分并应用它即可。

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

最新更新