-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class1.cs
129 lines (114 loc) · 4.68 KB
/
Class1.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace GridWithSolidGridLines
{
public class CustomGrid : Grid
{
#region GridLinesVisibilityEnum
public enum GridLinesVisibilityEnum
{
Both,
Vertical,
Horizontal,
None
}
#endregion
#region Properties
public bool ShowCustomGridLines
{
get { return (bool)GetValue(ShowCustomGridLinesProperty); }
set { SetValue(ShowCustomGridLinesProperty, value); }
}
public static readonly DependencyProperty ShowCustomGridLinesProperty =
DependencyProperty.Register("ShowCustomGridLines", typeof(bool),
typeof(CustomGrid), new UIPropertyMetadata(false));
public GridLinesVisibilityEnum GridLinesVisibility
{
get { return (GridLinesVisibilityEnum)GetValue(GridLinesVisibilityProperty); }
set { SetValue(GridLinesVisibilityProperty, value); }
}
public static readonly DependencyProperty GridLinesVisibilityProperty =
DependencyProperty.Register("GridLinesVisibility",
typeof(GridLinesVisibilityEnum), typeof(CustomGrid),
new UIPropertyMetadata(GridLinesVisibilityEnum.Both));
public Brush GridLineBrush
{
get { return (Brush)GetValue(GridLineBrushProperty); }
set { SetValue(GridLineBrushProperty, value); }
}
public static readonly DependencyProperty GridLineBrushProperty =
DependencyProperty.Register("GridLineBrush", typeof(Brush),
typeof(CustomGrid), new UIPropertyMetadata(Brushes.Black));
public double GridLineThickness
{
get { return (double)GetValue(GridLineThicknessProperty); }
set { SetValue(GridLineThicknessProperty, value); }
}
public static readonly DependencyProperty GridLineThicknessProperty =
DependencyProperty.Register("GridLineThickness", typeof(double),
typeof(CustomGrid), new UIPropertyMetadata(1.0));
#endregion
protected override void OnRender(DrawingContext dc)
{
if (ShowCustomGridLines)
{
if (GridLinesVisibility == GridLinesVisibilityEnum.Both)
{
foreach (var rowDefinition in RowDefinitions)
{
dc.DrawLine(new Pen(GridLineBrush, GridLineThickness),
new Point(0, rowDefinition.Offset),
new Point(ActualWidth, rowDefinition.Offset));
}
foreach (var columnDefinition in ColumnDefinitions)
{
dc.DrawLine(new Pen(GridLineBrush, GridLineThickness),
new Point(columnDefinition.Offset, 0),
new Point(columnDefinition.Offset, ActualHeight));
}
dc.DrawRectangle(Brushes.Transparent,
new Pen(GridLineBrush, GridLineThickness),
new Rect(0, 0, ActualWidth, ActualHeight));
}
else if (GridLinesVisibility == GridLinesVisibilityEnum.Vertical)
{
foreach (var columnDefinition in ColumnDefinitions)
{
dc.DrawLine(new Pen(GridLineBrush, GridLineThickness),
new Point(columnDefinition.Offset, 0),
new Point(columnDefinition.Offset, ActualHeight));
}
dc.DrawRectangle(Brushes.Transparent,
new Pen(GridLineBrush, GridLineThickness),
new Rect(0, 0, ActualWidth, ActualHeight));
}
else if (GridLinesVisibility == GridLinesVisibilityEnum.Horizontal)
{
foreach (var rowDefinition in RowDefinitions)
{
dc.DrawLine(new Pen(GridLineBrush, GridLineThickness),
new Point(0, rowDefinition.Offset),
new Point(ActualWidth, rowDefinition.Offset));
}
dc.DrawRectangle(Brushes.Transparent,
new Pen(GridLineBrush, GridLineThickness),
new Rect(0, 0, ActualWidth, ActualHeight));
}
else if (GridLinesVisibility == GridLinesVisibilityEnum.Horizontal)
{
}
}
base.OnRender(dc);
}
static CustomGrid()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomGrid),
new FrameworkPropertyMetadata(typeof(CustomGrid)));
}
}
}