Created
January 16, 2015 04:45
-
-
Save skendrot/9ba45cff2b430ccf6feb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WinRT Implementation of the base Behavior classes | |
public abstract class Behavior<T> : Behavior where T : DependencyObject | |
{ | |
protected T AssociatedObject | |
{ | |
get { return base.AssociatedObject as T; } | |
} | |
protected override void OnAttached() | |
{ | |
base.OnAttached(); | |
if (this.AssociatedObject == null) throw new InvalidOperationException("AssociatedObject is not of the right type"); | |
} | |
} | |
public abstract class Behavior : DependencyObject, IBehavior | |
{ | |
public void Attach(DependencyObject associatedObject) | |
{ | |
AssociatedObject = associatedObject; | |
OnAttached(); | |
} | |
public void Detach() | |
{ | |
OnDetaching(); | |
} | |
protected virtual void OnAttached() | |
{ | |
} | |
protected virtual void OnDetaching() | |
{ | |
} | |
protected DependencyObject AssociatedObject { get; set; } | |
DependencyObject IBehavior.AssociatedObject | |
{ | |
get { return this.AssociatedObject; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment