1

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

4

2 回答 2

2

是的。这是可能的。

如果您看这里,您可以获得现有复选框的完整样式,并且边框似乎不是由装饰器绘制的。因此,只需以您的风格更改此部分并应用它。

<Border x:Name="Border"
                Width="13"
                Height="13"
 <!--Here-->        CornerRadius="0"
                BorderThickness="1">
          <Border.BorderBrush>
于 2012-09-24T13:23:52.183 回答
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>
于 2012-09-24T13:21:30.883 回答