private async void IsComplete_Click(object sender, RoutedEventArgs e) { // There is two way data binding going on - so what we don't need to do is worry // about storing the data. This is purely about refreshing the view on the basis // of changes // The thing being clicked isn't necessarily selected. So we need to fix that CheckBox checkbox = e.OriginalSource as CheckBox; ListViewItem container = checkbox.AllAncestry().First(el => el is ListViewItem) as ListViewItem; // It is really important we mark the container as selected. If we don't then we // get crashes on sort. container.IsSelected = true; // Similarly we need to make a note of the selected action ActionItemManager.Selected = this.ActionItems.ItemFromContainer(container) as ActionItem; this.AlterSelectionIfRequired(); // Now sort and select ActionItemManager.Actions.Sort(); this.SelectActionItemAndScroll(); // And save await ActionItemManager.SaveAsync(); }
protected override async void OnNavigatedFrom(NavigationEventArgs e) { if (string.IsNullOrEmpty(this.ActionItem.Raw)) { ActionItemManager.Delete(this.ActionItem); } else { // Try and save first... await ActionItemManager.SaveAsync(); } // As you were base.OnNavigatedFrom(e); SystemNavigationManager.GetForCurrentView().BackRequested -= EditPage_BackRequested; }
private async void SelectedIsComplete_Toggle() { // Only do anything if something is selected otherwise badness will happen if (ActionItemManager.Selected != null) { // We do need to worry about setting data here since this is non-standard ActionItemManager.Selected.IsComplete = !ActionItemManager.Selected.IsComplete; this.AlterSelectionIfRequired(); // And save await ActionItemManager.SaveAsync(); // Now sort ActionItemManager.Actions.Sort(); this.SelectActionItemAndScroll(); } }
private async Task DeleteAsync() { IList <ActionItem> toBeDeleted = new List <ActionItem>(); // We have to make a temporary list of things to delete as doing so in the loop // will invalidate the IEnumerable foreach (ActionItem actionItem in this.ActionItems.SelectedItems) { toBeDeleted.Add(actionItem); } foreach (var actionItem in toBeDeleted) { ActionItemManager.Delete(actionItem); } await ActionItemManager.SaveAsync(); }