/
BlockBindingBase_T.cs
68 lines (59 loc) · 1.82 KB
/
BlockBindingBase_T.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
using DevZest.Data.Views;
using System.Diagnostics;
using System.Windows;
using System;
namespace DevZest.Data.Presenters.Primitives
{
/// <summary>
/// Base class for strongly type block binding.
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class BlockBindingBase<T> : BlockBinding
where T : UIElement, new()
{
private T Create()
{
var result = new T();
OnCreated(result);
return result;
}
/// <summary>
/// Gets the view element that is setting up.
/// </summary>
public T SettingUpElement { get; private set; }
internal sealed override UIElement GetSettingUpElement()
{
return SettingUpElement;
}
internal override void BeginSetup(UIElement value)
{
SettingUpElement = value == null ? Create() : (T)value;
}
internal override void EndSetup()
{
SettingUpElement = null;
}
internal sealed override UIElement Setup(BlockView blockView)
{
Debug.Assert(SettingUpElement != null);
SettingUpElement.SetBlockView(blockView);
PerformSetup(blockView);
return SettingUpElement;
}
internal abstract void PerformSetup(BlockView blockView);
/// <summary>
/// Gets the view element at specified block ordinal.
/// </summary>
/// <param name="blockOrdinal">The specified block ordinal.</param>
/// <returns>The view element.</returns>
public new T this[int blockOrdinal]
{
get { return (T)base[blockOrdinal]; }
}
/// <inheritdoc/>
public sealed override Type ViewType
{
get { return typeof(T); }
}
}
}