如何在WPF中绘制循环形状?

时间:2018-06-15 14:29:56

标签: c# wpf loops xaml drawing

我正在研究如何在代码隐藏中在WPF中绘制循环形状。

我知道我可以绘制椭圆并绘制一条线,但我找不到任何地方如何修改它们以获得这种循环形状。

也许我没有在这种类型的绘画中使用正确的单词...但是也找到了一些像回形针这样的词,但不确定这是否正是我正在寻找的......

欢迎任何提示。谢谢!

enter image description here

1 个答案:

答案 0 :(得分:1)

它有点笨拙,但你可以创建几何对象,然后从SVG数据创建Path对象。 然后可以将Path托管在任何容器中。

//Define SVG data
string pathData = "M 4.4285714e-6,196.64791 C 71.557031,196.64791 202.13304,-0.49493571 99.047621,-0.49493571 c -103.0854176,0 -4.93638,197.14284571 99.047619,197.14284571 103.984,0 197.9832,-197.14284571 99.04762,-197.14284571 -98.93558,0 3.94706,197.14284571 99.04762,197.14284571 95.10056,0 199.7498,-197.14284571 99.04761,-197.14284571 -100.70219,0 4.52998,197.14284571 99.04762,197.14284571";
//Create converter
var converter = TypeDescriptor.GetConverter(typeof(Geometry));

//Create Path
var p = new Path() {
    Data = (Geometry)converter.ConvertFrom(pathData),
    Stroke = new SolidColorBrush(Colors.Red),
    StrokeThickness = 4
};