Search code examples
wpfbackgroundgroupbox

Groupbox gradient background


I can't figure out how to make the background og the groupbox fade between almost transparent in the top and almost solid white in the bottom.

I want to set the background in a style like this one:

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

I hope you can help me.

PS: I am using C# with WPF 4


Solution

  • Hi FireFly i think you are not aware with the power of XAML its comes from xml so you can add any identified element under reconized tag. like

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

    or

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