/
CounterGrid.cs
115 lines (96 loc) · 2.54 KB
/
CounterGrid.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
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.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.Foundation;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
{
internal partial class CounterGrid : Grid
{
/// <summary>
/// How many instances of this type have been created?
/// </summary>
public static int CreationCount { get; private set; }
/// <summary>
/// How many times has an instance of this type been data-bound?
/// </summary>
public static int BindCount { get; private set; }
public static int GlobalMeasureCount { get; private set; }
public static int GlobalArrangeCount { get; private set; }
/// <summary>
/// How many times has this instance been data-bound?
/// </summary>
public int LocalBindCount { get; private set; }
public int LocalMeasureCount { get; private set; }
public int LocalArrangeCount { get; private set; }
/// <summary>
/// Raised whenever an instance of this type is created, data-bound, measured or arranged.
/// </summary>
public static event Action WasUpdated;
public CounterGrid()
{
CreationCount++;
WasUpdated?.Invoke();
DataContextChanged += On_DataContextChanged;
}
private void On_DataContextChanged(DependencyObject sender, DataContextChangedEventArgs args)
{
if (args.NewValue != null)
{
BindCount++;
LocalBindCount++;
WasUpdated?.Invoke();
}
}
protected override Size MeasureOverride(Size availableSize)
{
GlobalMeasureCount++;
LocalMeasureCount++;
WasUpdated?.Invoke();
return base.MeasureOverride(availableSize);
}
protected override Size ArrangeOverride(Size finalSize)
{
GlobalArrangeCount++;
LocalArrangeCount++;
WasUpdated?.Invoke();
return base.ArrangeOverride(finalSize);
}
/// <summary>
/// Reset static counters.
/// </summary>
public static void Reset()
{
CreationCount = 0;
BindCount = 0;
GlobalMeasureCount = 0;
GlobalArrangeCount = 0;
}
}
internal partial class CounterGrid2 : Grid
{
public static int CreationCount { get; private set; }
public static int BindCount { get; private set; }
public static event Action WasUpdated;
public CounterGrid2()
{
CreationCount++;
WasUpdated?.Invoke();
DataContextChanged += On_DataContextChanged;
}
private void On_DataContextChanged(DependencyObject sender, DataContextChangedEventArgs args)
{
if (args.NewValue != null)
{
BindCount++;
WasUpdated?.Invoke();
}
}
public static void Reset()
{
CreationCount = 0;
BindCount = 0;
}
}
}