Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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# WPF树视图删除绘制的线(重画)_C#_Wpf_Treeview_Drawingcontext - Fatal编程技术网

C# WPF树视图删除绘制的线(重画)

C# WPF树视图删除绘制的线(重画),c#,wpf,treeview,drawingcontext,C#,Wpf,Treeview,Drawingcontext,因为普通的TreeView不适合我的需要,我创建了自己的TreeView,从TreeView继承,并在我的TreeView项之间画线。像这样的 到目前为止还不错,但我想在构建和绘制树之后重新绘制删除添加线。目前,我在OnRender方法中执行所有操作,该方法已经提供了用于绘制线条的DrawingContext //Point connections from the parent to the childs. Point parentStart =

因为普通的TreeView不适合我的需要,我创建了自己的TreeView,从TreeView继承,并在我的TreeView项之间画线。像这样的

到目前为止还不错,但我想在构建和绘制树之后重新绘制删除添加线。目前,我在OnRender方法中执行所有操作,该方法已经提供了用于绘制线条的DrawingContext

            //Point connections from the parent to the childs.
            Point parentStart = parentCenter;
            Point parentEnd = new Point(parentCenter.X, middleParentChild);
            Point childEnd = new Point(childCenter.X, middleParentChild);
            Point childStart = childCenter;

            drawingContext.DrawLine(Pen, parentStart, parentEnd);
            drawingContext.DrawLine(Pen, parentEnd, childEnd);
            drawingContext.DrawLine(Pen, childEnd, childStart);

            //recursivly do this for all children
            DrawConnections(Pen, drawingContext, item);

但在控件呈现一次之后,我无法访问DrawingContext。保存在lokal变量中,我无法删除已绘制的形状,也无法重新绘制任何内容,因为DrawingContext已被释放。

您可以使用YourTreeView.InvalidateVisual重新绘制您的树。

哇,这很容易。谢谢