【问题标题】:Groupbox gradient background组框渐变背景
【发布时间】:2012-03-14 19:14:26
【问题描述】:

我不知道如何使组框的背景在顶部几乎透明和底部几乎纯白色之间渐变。

我想把背景设置成这样的样式:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <!--Groups and borders-->
    <Style x:Key="MainGroupBox" TargetType="{x:Type GroupBox}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderBrush" Value="Black" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
    </Style>

我希望你能帮助我。

PS:我在 WPF 4 中使用 C#

【问题讨论】:

标签: wpf background groupbox


【解决方案1】:

嗨,FireFly,我认为您不知道 XAML 的强大功能来自 xml,因此您可以在 reconized 标记下添加任何已识别的元素。喜欢

  <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush>
                        <GradientStop Offset="0.5" Color="Red" />
                        <GradientStop Offset="0.3" Color="Black" />
                        <GradientStop Offset="0.9" Color="Yellow" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>

<Setter Property="Background">
                <Setter.Value>
                    <RadialGradientBrush>
                        <GradientStop Offset="0.5" Color="Red" />
                        <GradientStop Offset="0.3" Color="Black" />
                        <GradientStop Offset="0.9" Color="Yellow" />
                    </RadialGradientBrush>
                </Setter.Value>
            </Setter>

【讨论】:

    【解决方案2】:

    你的风格需要:

    <Style x:Key="MainGroupBox" TargetType="{x:Type GroupBox}"> 
       <Setter Property="Background">
          <Setter.Value>
            <LinearGradientBrush>
              <GradientStop Color="Transparent" Offset="0"/>
              <GradientStop Color="White" Offset="1"/>
            </LinearGradientBrush>
          </Setter.Value>
       </Setter>
       ... other properties
    </Style>
    

    (我可能会崇敬颜色(我是凭记忆打字)

    【讨论】:

    • 如果我想要它的不透明度为 0.4 怎么办
    • @FireFly3000 - 您可以使用#aarrggbb 设置颜色,例如。 #3FFFFFFF
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 2012-03-31
    • 2011-03-15
    • 2012-12-31
    相关资源
    最近更新 更多