-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtraLayoutGroup.vb
More file actions
112 lines (98 loc) · 5.36 KB
/
ExtraLayoutGroup.vb
File metadata and controls
112 lines (98 loc) · 5.36 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
104
105
106
107
108
109
110
111
112
Imports System
Imports System.Collections.Generic
Imports System.Windows
Imports DevExpress.Xpf.LayoutControl
Imports System.Windows.Controls
Namespace DXSample
Public Class ExtraLayoutGroup
Inherits LayoutGroup
Public Property LayoutItemSize As GridLength
Get
Return CType(GetValue(LayoutItemSizeProperty), GridLength)
End Get
Set(ByVal value As GridLength)
SetValue(LayoutItemSizeProperty, value)
End Set
End Property
Public Shared ReadOnly LayoutItemSizeProperty As DependencyProperty = DependencyProperty.Register("LayoutItemSize", GetType(GridLength), GetType(ExtraLayoutGroup), New PropertyMetadata(New GridLength(0, GridUnitType.Star)))
Protected Overrides Function OnMeasure(ByVal constraint As Size) As Size
If constraint.Width = 0 AndAlso constraint.Height = 0 Then Return MyBase.OnMeasure(constraint)
Dim maxConstraint As Size = New Size(Double.PositiveInfinity, Double.PositiveInfinity)
Dim defaultConstraint As Size = constraint
constraint = MyBase.OnMeasure(constraint)
Dim minConstraint As Size = New Size(Math.Min(defaultConstraint.Width, constraint.Width), Math.Min(defaultConstraint.Height, constraint.Height))
Dim starCount As Double = 0
'#Region "Create GroupLists"
Dim listPixel As List(Of ExtraLayoutGroup) = New List(Of ExtraLayoutGroup)()
Dim listStar As List(Of ExtraLayoutGroup) = New List(Of ExtraLayoutGroup)()
For Each child As UIElement In Children
If TypeOf child Is ExtraLayoutGroup Then
Dim group As ExtraLayoutGroup = CType(child, ExtraLayoutGroup)
If TypeOf Parent Is ExtraLayoutControl Then
Select Case CType(Parent, ExtraLayoutControl).Orientation
Case Orientation.Horizontal
CType(child, FrameworkElement).HorizontalAlignment = HorizontalAlignment.Stretch
Case Orientation.Vertical
CType(child, FrameworkElement).VerticalAlignment = VerticalAlignment.Stretch
End Select
End If
If TypeOf Parent Is ExtraLayoutGroup Then
Select Case CType(Parent, ExtraLayoutGroup).Orientation
Case Orientation.Horizontal
CType(child, FrameworkElement).HorizontalAlignment = HorizontalAlignment.Stretch
Case Orientation.Vertical
CType(child, FrameworkElement).VerticalAlignment = VerticalAlignment.Stretch
End Select
End If
If group.LayoutItemSize.Value > 0 Then
Select Case group.LayoutItemSize.GridUnitType
Case GridUnitType.Pixel
listPixel.Add(CType(child, ExtraLayoutGroup))
Case GridUnitType.Star
listStar.Add(CType(child, ExtraLayoutGroup))
starCount += CType(child, ExtraLayoutGroup).LayoutItemSize.Value
End Select
End If
End If
Next
If listPixel.Count = 0 AndAlso listStar.Count = 0 Then Return constraint
'#End Region
'#Region "Resize Pixeled"
For Each group As ExtraLayoutGroup In listPixel
If Orientation = Orientation.Horizontal Then
group.Width = group.LayoutItemSize.Value
Else
group.Height = group.LayoutItemSize.Value
End If
group.InvalidateMeasure()
group.Measure(minConstraint)
Next
'#End Region
constraint = MyBase.OnMeasure(minConstraint)
minConstraint.Width = Math.Min(minConstraint.Width, constraint.Width)
minConstraint.Height = Math.Min(minConstraint.Height, constraint.Height)
If starCount = 0 Then Return minConstraint
Dim starSize As Double = 0
'#Region "Calc StarSize"
Dim usedSize As Double = If((Orientation = Orientation.Horizontal), constraint.Width, constraint.Height)
For Each group As ExtraLayoutGroup In listStar
usedSize -= If((Orientation = Orientation.Horizontal), group.DesiredSize.Width, group.DesiredSize.Height)
Next
Dim availableSize As Double =(If((Orientation = Orientation.Horizontal), minConstraint.Width, minConstraint.Height)) - usedSize
starSize = availableSize / starCount
'#End Region
'#Region "Resize Starred"
For Each group As ExtraLayoutGroup In listStar
If Orientation = Orientation.Horizontal Then
group.Width = group.LayoutItemSize.Value * starSize
Else
group.Height = group.LayoutItemSize.Value * starSize
End If
group.InvalidateMeasure()
group.Measure(If((Orientation = Orientation.Horizontal), New Size(group.Width, minConstraint.Height), New Size(minConstraint.Width, group.Height)))
Next
'#End Region
Return MyBase.OnMeasure(minConstraint)
End Function
End Class
End Namespace