-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtraLayoutControl.vb
More file actions
79 lines (70 loc) · 3.89 KB
/
ExtraLayoutControl.vb
File metadata and controls
79 lines (70 loc) · 3.89 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
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports DevExpress.Xpf.LayoutControl
Namespace DXSample
Public Class ExtraLayoutControl
Inherits DevExpress.Xpf.LayoutControl.LayoutControl
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)
If Double.IsInfinity(defaultConstraint.Width) AndAlso Orientation = Orientation.Horizontal Then defaultConstraint.Width = constraint.Width
If Double.IsInfinity(defaultConstraint.Height) AndAlso Orientation = Orientation.Vertical Then 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
If CType(child, ExtraLayoutGroup).LayoutItemSize.Value > 0 Then
Select Case CType(child, ExtraLayoutGroup).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(If((Orientation = Orientation.Horizontal), New Size(group.LayoutItemSize.Value, maxConstraint.Height), New Size(maxConstraint.Width, group.LayoutItemSize.Value)))
Next
'#End Region
constraint = MyBase.OnMeasure(defaultConstraint)
If starCount = 0 Then Return constraint
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), defaultConstraint.Width, defaultConstraint.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, maxConstraint.Height), New Size(maxConstraint.Width, group.Height)))
Next
'#End Region
Return MyBase.OnMeasure(constraint)
End Function
End Class
End Namespace