如何从后面的代码设置 WPF StrokeDashArray?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13372274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:11:07 来源:igfitidea点击:
How to set the WPF StrokeDashArray from Code behind?
提问by 0070
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.
我可以知道如何从后面的代码设置 StrokeDashArray 吗?我尝试使用类似于如何设置边距的方法......但它不起作用。
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);
}
回答by nmaait
Problem is this line
问题是这条线
myCircle.StrokeDashArray = new System.Windows.Thickness("2,2,2,2");
StrokeDashArray is a DoubleCollection
StrokeDashArray 是一个DoubleCollection
Try this instead
试试这个
myCircle.StrokeDashArray = new DoubleCollection() { 2 };

