Silverlight LinearGradientBrush Color not correct

95 views Asked by At

I want to use LinearGradientBrush to horizontal fill my Rectangle on canvas.

My code:

<Rectangle Width="200" Height="200">
    <Rectangle.Fill>
        <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5" >                   
            <GradientStop Color="Red" Offset="0" />
            <GradientStop Color="Blue" Offset="1" />                 
        </LinearGradientBrush>
    </Rectangle.Fill>
</Rectangle>

But I notice that the left-most color of red is not #FFFF0000, and it was #FFFE0000

enter image description here So did anyone know why this happen?

1

There are 1 answers

1
cptiv On BEST ANSWER

Gradient is drawn using interpolation, so it tends to the color you choose but it does not need to draw it exactly. It also depends on the size of the element for which you use the gradient.

Workaround - set Offset property as below:

<Rectangle Width="200" Height="200">
    <Rectangle.Fill>
        <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
            <GradientStop Color="Red" Offset="0.01" />
            <GradientStop Color="Blue" Offset="0.99"/>
        </LinearGradientBrush>
    </Rectangle.Fill>
</Rectangle>