forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBehavior.cs
More file actions
43 lines (35 loc) · 1.05 KB
/
Behavior.cs
File metadata and controls
43 lines (35 loc) · 1.05 KB
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
using Windows.UI.Xaml;
using Microsoft.Xaml.Interactivity;
using Windows.ApplicationModel;
using System;
namespace ReactiveUI.Blend
{
public class Behavior<T> : DependencyObject, IBehavior where T: DependencyObject
{
public virtual void Attach(DependencyObject associatedObject)
{
if (associatedObject == this.AssociatedObject || DesignMode.DesignModeEnabled) {
return;
}
if (this.AssociatedObject != null) {
throw new InvalidOperationException("Cannot attach multiple objects.");
}
AssociatedObject = associatedObject as T;
OnAttached();
}
public virtual void Detach()
{
OnDetaching();
}
protected virtual void OnAttached()
{
}
protected virtual void OnDetaching()
{
}
public T AssociatedObject { get; private set; }
DependencyObject IBehavior.AssociatedObject {
get { return this.AssociatedObject; }
}
}
}