wpfxamlgradientgradientstop

Absolute GradientStops in LinearGradientBrushes


How can I go about specifying absolute Offsets for the GradientStops in my LinearGradientBrush?

I have a GridView with a LinearGradientBrush as the background:

<Grid.Background>
    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStop Offset="0" Color="White" />
            <GradientStop Offset="0.25" Color="White" />
            <GradientStop Offset="0.4" Color="WhiteSmoke" />
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
</Grid.Background>

When the grid is at its default size, the white area of the gradient is about 60 pixel units tall. When I resize the grid, the gradient stretches and the white area gets larger. How can I keep the white area the same height, but stretch the rest of the gradient?

The white area corresponds to one row in the grid, so if there's a way to make the gradient span every row but the first one, that would work just fine.


Solution

  • I ended up splitting the Grid into multiple Grids to get the effect I wanted. The top grid had a white background, the middle had the gradient, and the bottom had the end color.