Last active
April 8, 2019 13:03
-
-
Save jamesmontemagno/10151686 to your computer and use it in GitHub Desktop.
MvvmCross Implementation of SwipleRefreshLayout for Xamarin.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
public class MvxSwipeRefreshLayout : SwipeRefreshLayout | |
{ | |
/// <summary> | |
/// Gets or sets the refresh command. | |
/// </summary> | |
/// <value>The refresh command.</value> | |
public ICommand RefreshCommand { get; set;} | |
public MvxSwipeRefreshLayout(Context context, IAttributeSet attrs) | |
: base(context, attrs) | |
{ | |
Init (); | |
} | |
public MvxSwipeRefreshLayout(Context context) | |
: base(context) | |
{ | |
Init (); | |
} | |
private void Init() | |
{ | |
//This gets called when we pull down to refresh to trigger command | |
this.Refresh += (object sender, EventArgs e) => { | |
var command = RefreshCommand; | |
if (command == null) | |
return; | |
command.Execute (null); | |
}; | |
} | |
} |
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
Update your .axml file: | |
<MeetupManager.Droid.Controls.MvxSwipeRefreshLayout | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:id="@+id/refresher" | |
local:MvxBind="Refreshing IsBusy"> | |
<Mvx.MvxGridView | |
..... /> | |
</MeetupManager.Droid.Controls.MvxSwipeRefreshLayout> | |
Code behind simply set your refresh command in your OnCreate(): | |
refresher = FindViewById<MvxSwipeRefreshLayout> (Resource.Id.refresher); | |
refresher.SetColorScheme (Resource.Color.xam_darkblue, | |
Resource.Color.xam_purple, | |
Resource.Color.xam_blue, | |
Resource.Color.xam_green); | |
refresher.RefreshCommand = ViewModel.RefreshCommand; | |
You can specify multiple colors for the refresh. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi James,
Hope doing well, i am trying to implement swipe to refresh in MvvmCross model,can you update the detailed steps to implement the Swipe to refresh control.thanks