Skip to content

Instantly share code, notes, and snippets.

@Christopherjl
Last active August 29, 2015 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Christopherjl/dc7922a910930c40175b to your computer and use it in GitHub Desktop.
Save Christopherjl/dc7922a910930c40175b to your computer and use it in GitHub Desktop.
Wpf inspired Behavor, For Android!
namespace Amp.Behaviors
{
public abstract class Behavior<T> : View where T:View
{
int _viewId;
protected Behavior(Context context, IAttributeSet attrs)
: base(context, attrs)
{
_viewId = context.ObtainStyledAttributes(attrs, Resource.Styleable.Behavior).GetResourceId(Resource.Styleable.Behavior_View,-1);
}
protected override void OnAttachedToWindow()
{
base.OnAttachedToWindow();
View =RootView.FindViewById<T>(_viewId);
OnAttached();
}
protected override void OnDetachedFromWindow()
{
base.OnDetachedFromWindow();
OnDetached();
}
public abstract void OnAttached();
public abstract void OnDetached();
public T View
{
get;
private set;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment