首页 > 解决方案 > Xaml:按钮角半径全局样式

问题描述

我在 xaml 中有以下代码来设置按钮的角半径。如何为应用程序中的所有按钮定义全局样式以具有恒定的角半径?

 <Button Content="Exit" MinWidth="65" Background="#b82c2c" Foreground="#fff" BorderThickness="0" 
  Height="25" VerticalAlignment="Bottom" >
                  <Button.Resources>
                          <Style TargetType="Border">
                                <Setter Property="CornerRadius" Value="5"/>
                          </Style>
                   </Button.Resources>
 </Button>

标签: wpfwindowsxamldesktop-application

解决方案


在 中声明具有边框样式的全局按钮样式Style.Resources

<Application.Resources>
    <Style TargetType="Button">
        <Style.Resources>
            <Style TargetType="Border">
                <Setter Property="CornerRadius" Value="5"/>
            </Style>
        </Style.Resources>
    </Style>
</Application.Resources>

推荐阅读