【问题标题】:Change button border thickness in wpf?更改wpf中的按钮边框厚度?
【发布时间】:2013-03-16 04:40:24
【问题描述】:

为什么Button的边框粗细没有变化?

如果我将边框粗细更改为 1 或 100,则无关紧要。一样的。我想使用 Style 来更改它,而不是 Custom Template

 <Window x:Class="GUI.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <Style x:Key="newYellowButton" TargetType="{x:Type Button}">
        <Setter Property="Width" Value="100"/>
        <Setter Property="Height" Value="100"/>
        <Setter Property="Background">
            <Setter.Value>
                <RadialGradientBrush Center="0.5,0.5" GradientOrigin="0.5,0.5" RadiusX="0.5" RadiusY="0.5" SpreadMethod="Pad" ColorInterpolationMode="SRgbLinearInterpolation">
                    <GradientStop Color="#FFEEEE3B" Offset="0.5" />
                    <GradientStop Color="#FFF0E49A" Offset="1" />
                </RadialGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderThickness" Value="9"/>
        <Setter Property="BorderBrush" Value="Blue" />
        <Setter Property="Padding" Value="-4"/>
    </Style>
</Window.Resources>
<Grid>
    <Button Style="{StaticResource newYellowButton}" Content="Ok"/>
</Grid>

【问题讨论】:

  • 对我来说很好,你发布的代码。还尝试更改 Style 中的 BorderThickness 并按预期输出。

标签: .net wpf button border thickness


【解决方案1】:

您可以通过更改Button's ControlTemplate 来实现。将这些样式、画笔和...复制到您的资源字典中,然后更改您想要的值。

要更改边框粗细,请找到以下代码并根据需要进行更改:

...
<Border 
      x:Name="Border"  
      CornerRadius="2" 
      BorderThickness="1"                             //CHANGE THIS VALUE
      Background="{StaticResource NormalBrush}"
      BorderBrush="{StaticResource NormalBorderBrush}">
      <ContentPresenter 
        Margin="2"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        RecognizesAccessKey="True"/>
</Border>
...

【讨论】:

  • 我只是想知道这是否可以在没有模板的情况下实现,只需使用样式。
  • 其实如果你点开链接你会发现,这是一个简单的风格。我编辑了我的帖子。
  • 非常感谢您的回答!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-24
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 2011-11-06
  • 1970-01-01
  • 2017-01-14
相关资源
最近更新 更多