Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// 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