-
Notifications
You must be signed in to change notification settings - Fork 6
/
RowViewPanel.cs
93 lines (81 loc) · 2.49 KB
/
RowViewPanel.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
using DevZest.Data.Presenters;
using DevZest.Data.Presenters.Primitives;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
namespace DevZest.Data.Views.Primitives
{
/// <summary>
/// Represents panel of <see cref="RowView"/>.
/// </summary>
public class RowViewPanel : FrameworkElement
{
/// <summary>
/// Initializes a new instance of <see cref="RowViewPanel"/> class.
/// </summary>
public RowViewPanel()
{
}
private RowView RowView
{
get { return TemplatedParent as RowView; }
}
private RowPresenter RowPresenter
{
get { return RowView?.RowPresenter; }
}
private LayoutManager LayoutManager
{
get
{
var rowPresenter = RowPresenter;
return rowPresenter == null ? null : rowPresenter.LayoutManager;
}
}
internal IReadOnlyList<UIElement> Elements
{
get
{
var rowView = RowView;
if (rowView == null)
return Array.Empty<UIElement>();
return rowView.Elements ?? Array.Empty<UIElement>();
}
}
/// <inheritdoc/>
protected override int VisualChildrenCount
{
get { return Elements.Count; }
}
/// <inheritdoc/>
protected override Visual GetVisualChild(int index)
{
if (index < 0 || index >= VisualChildrenCount)
throw new ArgumentOutOfRangeException(nameof(index));
return Elements[index];
}
/// <inheritdoc/>
protected override Size MeasureOverride(Size availableSize)
{
var layoutManager = LayoutManager;
if (layoutManager != null)
{
if (layoutManager.IsMeasuring)
return layoutManager.Measure(RowView, availableSize);
else
layoutManager.InvalidateMeasure();
}
return base.MeasureOverride(availableSize);
}
/// <inheritdoc/>
protected override Size ArrangeOverride(Size finalSize)
{
var layoutManager = LayoutManager;
if (layoutManager == null)
return base.ArrangeOverride(finalSize);
layoutManager.ArrangeChildren(RowView);
return finalSize;
}
}
}