-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFrameworkTemplate.cs
116 lines (102 loc) · 3.85 KB
/
FrameworkTemplate.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
116
using Appercode.UI.Controls;
using System;
using System.Windows;
namespace Appercode.UI
{
public abstract partial class FrameworkTemplate : DependencyObject
{
#region Declarations
private InternalFlags flags;
private FrameworkElementFactory templateRoot;
[Flags]
private enum InternalFlags : uint
{
CanBuildVisualTree = 4,
HasLoadedChangeHandler = 8,
HasContainerResourceReferences = 16,
HasChildResourceReferences = 32
}
#endregion
#region Properties
/// <summary>Gets or sets the root node of the template.</summary>
/// <returns>The root <see cref="FrameworkElementFactory"/> of the template.</returns>
public FrameworkElementFactory VisualTree
{
get
{
this.VerifyAccess();
return this.templateRoot;
}
set
{
this.VerifyAccess();
this.CheckSealed();
this.templateRoot = value;
}
}
public new bool IsSealed { get; private set; }
#region Internal members
internal bool CanBuildVisualTree
{
get { return this.ReadInternalFlag(InternalFlags.CanBuildVisualTree); }
set { this.WriteInternalFlag(InternalFlags.CanBuildVisualTree, value); }
}
#endregion
#endregion
#region Methods
/// <summary>Locks the template so it cannot be changed.</summary>
public new void Seal()
{
this.VerifyAccess();
this.IsSealed = true;
////StyleHelper.SealTemplate(this, ref this._sealed, this._templateRoot, this.TriggersInternal, this._resources, this._childIndexFromChildName, ref this.ChildRecordFromChildIndex, ref this.TriggerSourceRecordFromChildIndex, ref this.ContainerDependents, ref this.ResourceDependents, ref this.EventDependents, ref this._triggerActions, ref this._dataTriggerRecordFromBinding, ref this._hasInstanceValues, ref this._eventHandlersStore);
}
/// <summary>Loads the content of the template as an instance of an object and returns the root element of the content.</summary>
/// <returns>The root element of the content. Calling this multiple times returns separate instances.</returns>
public virtual DependencyObject LoadContent()
{
this.VerifyAccess();
this.Seal();
if (this.VisualTree == null)
{
return null;
}
var content = this.VisualTree.InstantiateUnoptimizedTree();
var uiElement = content as UIElement;
if (uiElement != null)
{
uiElement.IsTemplateRoot = true;
}
return content;
}
#endregion
internal virtual bool BuildVisualTree(UIElement container)
{
return false;
}
internal void CheckSealed()
{
if (this.IsSealed)
{
throw new InvalidOperationException("Template can't be changed after Sealed");
}
}
#region Implementation
private bool ReadInternalFlag(InternalFlags reqFlag)
{
return (int)(this.flags & reqFlag) != 0;
}
private void WriteInternalFlag(InternalFlags reqFlag, bool set)
{
if (set)
{
var frameworkTemplate = this;
frameworkTemplate.flags = frameworkTemplate.flags | reqFlag;
return;
}
var frameworkTemplate1 = this;
frameworkTemplate1.flags = frameworkTemplate1.flags & ~reqFlag;
}
#endregion
}
}