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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace RealTimeGraphX.WPF.Components
{
/// <summary>
/// Represents a panel that will align its children in an axis like arrangement.
/// </summary>
/// <seealso cref="System.Windows.Controls.Grid" />
public class GraphAxisPanel : Grid
{
/// <summary>
/// Gets or sets the panel orientation.
/// </summary>
public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
set { SetValue(OrientationProperty, value); }
}
public static readonly DependencyProperty OrientationProperty =
DependencyProperty.Register("Orientation", typeof(Orientation), typeof(GraphAxisPanel), new PropertyMetadata(Orientation.Vertical));
/// <summary>
/// Initializes a new instance of the <see cref="GraphAxisPanel"/> class.
/// </summary>
public GraphAxisPanel()
{
Loaded += VerticalAxisPanel_Loaded;
}
/// <summary>
/// Handles the Loaded event of the VerticalAxisGrid control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void VerticalAxisPanel_Loaded(object sender, RoutedEventArgs e)
{
UpdatePanel();
}
/// <summary>
/// Updates the panel.
/// </summary>
private void UpdatePanel()
{
RowDefinitions.Clear();
ColumnDefinitions.Clear();
if (Orientation == Orientation.Vertical)
{
for (int i = 0; i < InternalChildren.Count; i++)
{
FrameworkElement element = InternalChildren[i] as FrameworkElement;
if (i < InternalChildren.Count - 1)
{
RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
Grid.SetRow(element, i);
element.VerticalAlignment = VerticalAlignment.Top;
element.SizeChanged += (_, __) =>
{
element.Margin = new Thickness(0, (element.ActualHeight / 2) * -1, 0, 0);
};
}
else
{
Grid.SetRow(element, i);
element.VerticalAlignment = VerticalAlignment.Bottom;
element.SizeChanged += (_, __) =>
{
element.Margin = new Thickness(0, 0, 0, (element.ActualHeight / 2) * -1);
};
}
}
}
else
{
for (int i = 0; i < InternalChildren.Count; i++)
{
FrameworkElement element = InternalChildren[i] as FrameworkElement;
if (i < InternalChildren.Count - 1)
{
ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
Grid.SetColumn(element, i);
element.HorizontalAlignment = HorizontalAlignment.Left;
element.SizeChanged += (_, __) =>
{
element.Margin = new Thickness((element.ActualWidth / 2) * -1, 0, 0, 0);
};
}
else
{
Grid.SetColumn(element, i);
element.HorizontalAlignment = HorizontalAlignment.Right;
element.SizeChanged += (_, __) =>
{
element.Margin = new Thickness(0, 0, (element.ActualWidth / 2) * -1, 0);
};
}
}
}
}
}
}
|