Created
November 3, 2020 12:33
-
-
Save khle/5cead71e8908f2d9231c09901e511ae3 to your computer and use it in GitHub Desktop.
MainPageViewModel
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
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