Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the WPF StrokeDashArray from Code behind?

Tags:

c#

wpf

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);
        main.MyCanvas.Children.Add(myCircle);

    }
like image 563
0070 Avatar asked Nov 14 '12 02:11

0070


1 Answers

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 };
like image 117
nmaait Avatar answered Oct 13 '22 20:10

nmaait