【问题标题】:Xaml: Button corner radius global styleXaml:按钮角半径全局样式
【发布时间】:2020-06-04 09:23:21
【问题描述】:

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

【问题讨论】:

  • @Clemens 它不适用于 App.xaml 中的边框。注意结构。当我设置 Property="Border" 时,它说成员无法识别或无法访问。

标签: wpf windows xaml desktop-application


【解决方案1】:

Style.Resources 中声明一个带边框样式的全局按钮样式:

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

【讨论】:

  • 代码似乎正确。但实际上不起作用!你自己试过吗?当我从按钮本身删除资源时,边框将是默认的
猜你喜欢
  • 2013-12-13
  • 1970-01-01
  • 1970-01-01
  • 2018-07-05
  • 1970-01-01
  • 1970-01-01
  • 2015-02-04
  • 1970-01-01
  • 2014-04-24
相关资源
最近更新 更多