Skip to content

Instantly share code, notes, and snippets.

@khle
Created November 3, 2020 12:33
Show Gist options
  • Save khle/5cead71e8908f2d9231c09901e511ae3 to your computer and use it in GitHub Desktop.
Save khle/5cead71e8908f2d9231c09901e511ae3 to your computer and use it in GitHub Desktop.
MainPageViewModel
using Xamarin.Forms;
using System.ComponentModel;
using System.Threading.Tasks;
namespace AsyncButtonApp.ViewModels
{
public class MainPageViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public Command FetchCommand { get; }
public MainPageViewModel()
{
FetchCommand = new Command(async (obj) => await OnFetchClicked(obj));
}
private async Task OnFetchClicked(object obj)
{
IsFetching = true;
await Task.Delay(1500); //simulates some async work
IsFetching = false;
}
private bool _isFetching;
public bool IsFetching
{
get { return _isFetching; }
set
{
_isFetching = value;
OnPropertyChanged(nameof(IsFetching));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment