Pen pen = new Pen(Brushes.Red, 2); drawingContext.DrawLine(pen, new Point(0, 0), new Point(100, 100));
Pen pen = new Pen(new LinearGradientBrush(Colors.Blue, Colors.Green, new Point(0,0), new Point(1,1)), 2); pen.DashStyle = new DashStyle(new double[] { 4, 2 }, 0); drawingContext.DrawLine(pen, new Point(0, 0), new Point(100, 100));In this example, we create a Pen object with a LinearGradientBrush that fades from blue to green. We then set the pen's DashStyle property to a dashed pattern of 4 pixels on and 2 pixels off, and draw a line using the pen. Overall, the Pen class is a versatile tool for defining line styles in C# applications. It can be used in conjunction with various brush types and dash styles to create a wide range of visual effects.