【问题标题】:Button with rounded corners in code-behind代码隐藏中的圆角按钮
【发布时间】:2012-08-19 04:56:17
【问题描述】:

我需要帮助才能在 WPF 中创建带圆角的按钮。我想在上面使用渐变背景!

我需要在后面的代码中设置它,而不是在 XAML 中。会在运行时设置,不知道要创建多少个按钮。

【问题讨论】:

    标签: wpf button code-behind


    【解决方案1】:

    因为会在运行时创建,所以我不知道要创建多少个按钮。

    这不是 WPF 中的正当理由,有一个叫做 data-templating 的东西。

    【讨论】:

      【解决方案2】:

      您只需要为您的按钮创建一个默认样式(在您的情况下为四舍五入)。 比如要修改Button控件

      在您的主题中 (Generic.xaml)

      <Style TargetType="{x:Type Button}">
          <Setter Property="Template">
              <Setter.Value>
                  <ControlTemplate TargetType="{x:Type Button}">
                       // Your button style
                  </ControlTemplate>
              </Setter.Value>
          </Setter>
      </Style>
      

      然后,每次添加新按钮时,都会使用这个主题。

      【讨论】:

        猜你喜欢
        • 2015-04-01
        • 2018-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多