Pergunta

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

Foi útil?

Solução

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>

Outras dicas

Your style needs to be:

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

(I may have the colours revered (I'm typing from memory)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top