Hey all,
I'm working in WPF, but since this question is all about the code behind it makes sense to post it here.

I need to make area gradient using the System.Windows.Media namespace. Essential it would be a LinearGradient in both the horizontal and vertical directions simultaneously.

I have this code that produces the image below...
VB.Net Code:
  1. Dim br As New LinearGradientBrush()
  2.  
  3. Dim startP As New Point(0, 0.5)
  4. Dim endP As New Point(1, 0.5)
  5. br.StartPoint = startP
  6. br.EndPoint = endP
  7.  
  8. br.GradientStops.Add(New GradientStop(Colors.Transparent, 0.0))
  9. br.GradientStops.Add(New GradientStop(Colors.Red, 0.2))
  10. br.GradientStops.Add(New GradientStop(Colors.Red, 0.8))
  11. br.GradientStops.Add(New GradientStop(Colors.Transparent, 1))
  12.  
  13. _rectangle.Fill = br
Name:  gradient.png
Views: 682
Size:  841 Bytes


I don't know how to draw the gradient once, then rotate it and redraw it again without covering the first.

If I were in the System.Drawing namespace I would create 4 triangles paths in the rectangle each rotated by 90 degrees and fill them with a gradient to produce the results. Being new to the Media namespace however, I don't see how to create a path like this.

Any one know how to create a area gradient like what I describe?

(VS2019 btw)