async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { Notes.Clear(); var notes = await NoteDataStore.GetNotesAsync(); foreach (var note in notes) { Notes.Add(note); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public ItemsViewModel() { Title = "NoteKeeper"; Notes = new ObservableCollection <Note>(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "SaveNote", async(sender, note) => { Notes.Add(note); await NoteDataStore.AddNoteAsync(note); } ); MessagingCenter.Subscribe <ItemDetailPage, Note>(this, "UpdateNote", async(sender, note) => { await NoteDataStore.UpdateNoteAsync(note); await ExecuteLoadItemsCommand(); } ); }
async void InitializeCourseList() { CourseList = await NoteDataStore.GetCoursesAsync(); }