Line with different solid colors, solidcolorbrush with gradient stops but without the gradients
-
19-09-2019 - |
Question
In Silverlight (version 3 preview), I want to create a Line with different solid colors, so no gradients between colors.
Basically I want to do the following:
<Line X1="0" X2="500" StrokeThickness="10">
<Line.Stroke>
<LinearGradientBrush>
<GradientStop Color="Blue" Offset="0.5" />
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</Line.Stroke>
</Line>
But with a discrete change in color, and not the gradual change from blue to red
I wonder if this is possible without resorting to using multiple lines?
Solution
What you're looking for is this
<Line.Stroke>
<LinearGradientBrush>
<GradientStop Color="Blue" Offset="0.5" />
<GradientStop Color="Red" Offset="0.5" />
</LinearGradientBrush>
</Line.Stroke>
By setting the stops on top of each other they don't have space in which to transition from the one to the other.
Hope this helps.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow