-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleGrid.cs
More file actions
103 lines (94 loc) · 4.17 KB
/
SimpleGrid.cs
File metadata and controls
103 lines (94 loc) · 4.17 KB
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
using System.Windows;
using System.Windows.Controls;
namespace WpfApp1
{
public class SimpleGrid : Grid
{
// The direction of stacking
public static readonly DependencyProperty IsLayoutSuppressedProperty =
DependencyProperty.Register("IsLayoutSuppressed", typeof(bool),
typeof(SimpleGrid), new FrameworkPropertyMetadata(
false, FrameworkPropertyMetadataOptions.AffectsMeasure));
public bool IsLayoutSuppressed
{
get { return (bool)GetValue(IsLayoutSuppressedProperty); }
set { SetValue(IsLayoutSuppressedProperty, value); }
}
private Size _cachedAvailableSize = Size.Empty;
protected override Size MeasureOverride(Size availableSize)
{
if (!IsLayoutSuppressed)
{
_cachedAvailableSize = base.MeasureOverride(availableSize);
}
return _cachedAvailableSize;
// Size desiredSize = new Size();
// // Let children grow indefinitely in the direction of stacking,
// // overwriting what was passed in
// if (Orientation == Orientation.Vertical)
// availableSize.Height = Double.PositiveInfinity;
// else
//availableSize.Width = Double.PositiveInfinity;
// foreach (UIElement child in this.Children)
// {
// if (child != null)
// {
// // Ask the first child for its desired size, given unlimited space in
// // the direction of stacking and all our available space (whatever was
// // passed in) in the other direction
// child.Measure(availableSize);
// // Our desired size is the sum of child sizes in the direction of
// // stacking, and the size of the largest child in the other direction
// if (Orientation == Orientation.Vertical)
// {
// desiredSize.Width = Math.Max(desiredSize.Width,
// child.DesiredSize.Width);
// desiredSize.Height += child.DesiredSize.Height;
// }
// else
// {
// desiredSize.Height = Math.Max(desiredSize.Height,
// child.DesiredSize.Height);
// desiredSize.Width += child.DesiredSize.Width;
// }
// }
// }
// return desiredSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
if (!IsLayoutSuppressed)
{
base.ArrangeOverride(finalSize);
}
return finalSize;
//double offset = 0;
//foreach (UIElement child in this.Children)
//{
// if (child != null)
// {
// if (Orientation == Orientation.Vertical)
// {
// // The offset moves the child down the stack.
// // Give the child all our width, but as much height as it desires.
// child.Arrange(new Rect(0, offset, finalSize.Width,
// child.DesiredSize.Height));
// // Update the offset for the next child
// offset += child.DesiredSize.Height;
// }
// else
// {
// // The offset moves the child down the stack.
// // Give the child all our height, but as much width as it desires.
// child.Arrange(new Rect(offset, 0, child.DesiredSize.Width,
// finalSize.Height));
// // Update the offset for the next child
// offset += child.DesiredSize.Width;
// }
// }
//}
//// Fill all the space given
//return finalSize;
}
}
}