我可以知道如何从代码中设置StrokeDashArray吗?我尝试使用方法,如设置边距的方式......但它不起作用。
以下是我的代码:
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);
}
答案 0 :(得分:16)
问题在于这一行
myCircle.StrokeDashArray = new System.Windows.Thickness("2,2,2,2");
StrokeDashArray是DoubleCollection
试试这个
myCircle.StrokeDashArray = new DoubleCollection() { 2 };