【问题标题】:WPF TreeView Remove drawn lines (ReDraw)WPF TreeView 删除画线(ReDraw)
【发布时间】:2017-09-01 12:22:34
【问题描述】:

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

到目前为止一切都很好,但我想在构建和绘制树之后重新绘制(删除添加线)。目前我在 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 已被释放。

【问题讨论】:

    标签: c# wpf treeview drawingcontext


    【解决方案1】:

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

    【讨论】:

    • 哇,这很容易。谢谢
    猜你喜欢
    • 1970-01-01
    • 2011-03-30
    • 2023-04-07
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 2016-07-05
    • 1970-01-01
    相关资源
    最近更新 更多