Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 向xaml动态添加线段_C#_Wpf_Xaml - Fatal编程技术网

C# 向xaml动态添加线段

C# 向xaml动态添加线段,c#,wpf,xaml,C#,Wpf,Xaml,我在可视化画布上包含多个线段的路径时遇到问题 现在,用户可以通过直接路径连接画布上的两个控件。这是通过创建viewmodel类的实例来完成的,该实例被传递给templateselector,templateselector返回路径的datatemplate 此模板看起来像 <Path StrokeThickness="2" Stroke="Black" Fill="Black" MinWidth="1" Min

我在可视化画布上包含多个线段的路径时遇到问题

现在,用户可以通过直接路径连接画布上的两个控件。这是通过创建viewmodel类的实例来完成的,该实例被传递给templateselector,templateselector返回路径的datatemplate

此模板看起来像

<Path StrokeThickness="2"
          Stroke="Black"
          Fill="Black"
          MinWidth="1"
          MinHeight="1"
          Name="arrowPath">
        <Path.Data>
            <PathGeometry>
                <PathGeometry.Figures>
                    <PathFigureCollection>
                        <PathFigure IsClosed="False"
                                    StartPoint="{Binding Path=Source, ElementName=_this}">
                            <PathFigure.Segments>
                                <PathSegmentCollection>
                                    <LineSegment IsStroked="True"
                                                 Point="{Binding Path=Destination, ElementName=_this}" />
                                </PathSegmentCollection>
                            </PathFigure.Segments>
                        </PathFigure>
                        <PathFigure IsClosed="True"
                                    IsFilled="True"
                                    StartPoint="{Binding Path=Destination, ElementName=_this}">
                            <PathFigure.Segments>
                                <PathSegmentCollection>
                                    <LineSegment IsSmoothJoin="True"
                                                 IsStroked="True"
                                                 Point="{Binding Path=TrianglePoint2, ElementName=_this}" />
                                    <LineSegment IsSmoothJoin="True"
                                                 IsStroked="True"
                                                 Point="{Binding Path=TrianglePoint3, ElementName=_this}" />
                                </PathSegmentCollection>
                            </PathFigure.Segments>
                        </PathFigure>
                    </PathFigureCollection>
                </PathGeometry.Figures>
            </PathGeometry>
        </Path.Data>
    </Path>
路径的开始和结束属性绑定到viewmodel实例的属性

到目前为止一切正常。但是有了更多的控件,画布真的是一团糟,我想让用户有机会通过由多个线段组成的路径连接控件。新的viewmodel类在列表中单击时存储鼠标位置

设计新控件时,我不知道如何在xaml中为列表中的每个点动态添加线段

我希望您理解我的意思,谢谢。

考虑一下,它包含一个关于创建图表设计器的分步教程,包括以及如何在UI中对它们建模