Last active
August 29, 2015 14:15
-
-
Save Christopherjl/dc7922a910930c40175b to your computer and use it in GitHub Desktop.
Wpf inspired Behavor, For Android!
This file contains hidden or 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
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