Skip to content

Instantly share code, notes, and snippets.

@tugcearar
Created July 15, 2018 13:13
Show Gist options
  • Save tugcearar/f89f48ec92dc1bb51ab924daaa5bd16a to your computer and use it in GitHub Desktop.
Save tugcearar/f89f48ec92dc1bb51ab924daaa5bd16a to your computer and use it in GitHub Desktop.
public class ListViewPageViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName]string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
private IList<Birds> birdsList;
bool isRefreshing;
private bool isEmpty;
public bool IsEmpty
{
get { return isEmpty; } set { isEmpty = value; OnPropertyChanged(); }
}
public IList<Birds> BirdsList
{
get { return birdsList; }
set { birdsList = value; OnPropertyChanged(); }
}
public bool IsRefreshing
{
get
{
return isRefreshing;
}
set
{
isRefreshing = value;
OnPropertyChanged();
}
}
public Command RefreshCommand { get; set; }
public ListViewPageViewModel()
{
BirdsList = new ObservableCollection<Birds>();
RefreshCommand = new Command(() => GetData());
GetData();
}
void GetData()
{
IsRefreshing = true;
birdsList.Clear();
Random random = new Random();
int number = random.Next(0, 4);
for (int i = 0; i < number; i++)
{
BirdsList.Add(new Birds
{
Title = "Quetzal",
Description = "The Quetzal are shockingly colored birds common in western Mexico and Guatemala. Historically, they were sacred to the Mayan and Aztec people, who believed that the Quetzal was the God of Air, and they used their green tail feathers in spiritual ceremonies. The bird inhabits the cold mountain woods, and during the dry seasons, it perches at a height of nearly 10,000 feet!",
});
}
IsEmpty = BirdsList.Count == 0;
IsRefreshing = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment