0070 0070 - 1 year ago 440
C# Question

How to set the WPF StrokeDashArray from Code behind?

Can i know how to set the StrokeDashArray from code behind? I try to use the method like the way how to set the margin...but it doesn't work.

The following is my code:

public static void DrawCircle(MainWindow main)
Ellipse myCircle = new Ellipse();
myCircle.Stroke = Brushes.Orange;
myCircle.Width = 25;
myCircle.Height = 25;
myCircle.StrokeThickness = 2;
myCircle.StrokeDashArray = new System.Windows.Thickness("2,2,2,2");

Canvas.SetLeft(myCircle, 10);
Canvas.SetRight(myCircle, 10);
Canvas.SetBottom(myCircle, 20);
Canvas.SetTop(myCircle, 20);


Answer Source

Problem is this line

myCircle.StrokeDashArray = new System.Windows.Thickness("2,2,2,2");

StrokeDashArray is a DoubleCollection

Try this instead

myCircle.StrokeDashArray = new DoubleCollection() { 2 };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download