-
-
Save matthieugd/3536efd83706e659e142 to your computer and use it in GitHub Desktop.
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
Snippet Name: Android Behavior - WPF Style | |
Platform(s): Xamarin.Android | |
Function: Reproduce the beloved WPF behaviors in Android | |
Snippet: | |
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; | |
} | |
} | |
Exemple of Usage: behavior to hide the keyboard when scrolling a listview | |
<com.mycompany.behaviors.ListViewHideKeyboardOnScroll | |
android:layout_width="0px" | |
android:layout_height="0px" | |
local:View="@+id/resultsList" /> | |
Credit : Chris in-house Rockstar Developer Lamothe | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment