-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathControlTemplate.cs
42 lines (37 loc) · 1.33 KB
/
ControlTemplate.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
using Appercode.UI.Controls;
using System;
using System.Windows;
namespace Appercode.UI
{
/// <summary>
/// Specifies the visual structure of a Control that can be shared across multiple instances of the control.
/// </summary>
public class ControlTemplate : FrameworkTemplate
{
public static readonly DependencyProperty TargetTypeProperty =
DependencyProperty.Register("TargetType", typeof(Type), typeof(ControlTemplate), new PropertyMetadata(typeof(Type)));
public Type TargetType
{
get { return (Type)this.GetValue(TargetTypeProperty); }
set { this.SetValue(TargetTypeProperty, value); }
}
public override DependencyObject LoadContent()
{
var content = base.LoadContent();
var uiElement = content as UIElement;
if (uiElement != null)
{
uiElement.ParentChanged += this.ContentParentChanged;
}
return content;
}
private void ContentParentChanged(object sender, EventArgs e)
{
var uiElement = sender as UIElement;
if (uiElement != null && uiElement.Parent != null)
{
this.VisualTree.SetTemplateBindings(uiElement.Parent);
}
}
}
}