C# WPF树视图删除绘制的线(重画)
因为普通的TreeView不适合我的需要,我创建了自己的TreeView,从TreeView继承,并在我的TreeView项之间画线。像这样的 到目前为止还不错,但我想在构建和绘制树之后重新绘制删除添加线。目前,我在OnRender方法中执行所有操作,该方法已经提供了用于绘制线条的DrawingContextC# 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 =
//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重新绘制您的树。哇,这很容易。谢谢