I'm trying to create a line with a 'barber shop pole' gradient effect in C# (WPF). The code below works, but when I move the line the gradient becomes distorted. Is there a way to move/rotate the line object and have the gradient's angle remain stationary relative to the line itself.
// Create a linear gradient brush
LinearGradientBrush redWhiteStripes = new LinearGradientBrush();
redWhiteStripes.StartPoint = new Point(0, 0);
redWhiteStripes.EndPoint = new Point(1, 1);
redWhiteStripes.SpreadMethod = GradientSpreadMethod.Reflect;
ScaleTransform s = new ScaleTransform();
s.ScaleX = 0.125;
s.ScaleY = 0.125;
RotateTransform rot = new RotateTransform();
rot.Angle = 20;
rot.CenterX = 0.0625;
rot.CenterY = 0.0625;
TransformGroup tgroup = new TransformGroup();
tgroup.Children.Add(s);
tgroup.Children.Add(rot);
redWhiteStripes.RelativeTransform = tgroup;
// Create and add Gradient stops
GradientStop point1 = new GradientStop();
point1.Color = Colors.DarkRed;
point1.Offset = 0.0;
redWhiteStripes.GradientStops.Add(point1);
// Create and add Gradient stops
GradientStop point2 = new GradientStop();
point2.Color = Colors.DarkRed;
point2.Offset = 0.5;
redWhiteStripes.GradientStops.Add(point2);
// Create and add Gradient stops
GradientStop point3 = new GradientStop();
point3.Color = Colors.White;
point3.Offset = 0.5;
redWhiteStripes.GradientStops.Add(point3);
// Create and add Gradient stops
GradientStop point4 = new GradientStop();
point4.Color = Colors.White;
point4.Offset = 1.0;
redWhiteStripes.GradientStops.Add(point4);
Line l = new Line();
l.Stroke = redWhiteStripes;
l.StrokeThickness = 8;