forked from dnSpy/ICSharpCode.TreeView
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLinesRenderer.cs
65 lines (55 loc) · 1.66 KB
/
LinesRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
namespace ICSharpCode.TreeView
{
class LinesRenderer : FrameworkElement
{
static LinesRenderer()
{
pen = new Pen(Brushes.LightGray, 1);
pen.Freeze();
}
static Pen pen;
SharpTreeNodeView NodeView
{
get { return TemplatedParent as SharpTreeNodeView; }
}
protected override void OnRender(DrawingContext dc)
{
if (NodeView.Node == null) {
// This seems to happen sometimes with DataContext==DisconnectedItem,
// though I'm not sure why WPF would call OnRender() on a disconnected node
Debug.WriteLine($"LinesRenderer.OnRender() called with DataContext={NodeView.DataContext}");
return;
}
var indent = NodeView.CalculateIndent(NodeView.Node);
var p = new Point(indent + 4.5, 0);
if (!NodeView.Node.IsRoot || NodeView.ParentTreeView.ShowRootExpander) {
dc.DrawLine(pen, new Point(p.X, ActualHeight / 2), new Point(p.X + 10, ActualHeight / 2));
}
if (NodeView.Node.IsRoot) return;
if (NodeView.Node.IsLast) {
dc.DrawLine(pen, p, new Point(p.X, ActualHeight / 2));
}
else {
dc.DrawLine(pen, p, new Point(p.X, ActualHeight));
}
var current = NodeView.Node;
while (true) {
p.X -= 19;
current = current.Parent;
if (p.X < 0) break;
if (!current.IsLast) {
dc.DrawLine(pen, p, new Point(p.X, ActualHeight));
}
}
}
}
}