Skip to content

Instantly share code, notes, and snippets.

@jamesmontemagno
Last active April 8, 2019 13:03
Show Gist options
  • Save jamesmontemagno/10151686 to your computer and use it in GitHub Desktop.
Save jamesmontemagno/10151686 to your computer and use it in GitHub Desktop.
MvvmCross Implementation of SwipleRefreshLayout for Xamarin.Android
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);
};
}
}
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.
@sureshkumar85ios
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment