private void appBarOkButton_Click(object sender, EventArgs e) { // Confirm there is some text in the text box. if (newTaskNameTextBox.Text.Length > 0) { // Create a new to-do item. ToDoItem newToDoItem = new ToDoItem { ItemName = newTaskNameTextBox.Text, Category = (ToDoCategory)categoriesListPicker.SelectedItem }; // Add the item to the ViewModel. App.ViewModel.AddToDoItem(newToDoItem); // Return to the main page. if (NavigationService.CanGoBack) { NavigationService.GoBack(); } } }
public void DeleteToDoItem(ToDoItem toDoForDelete) { // Remove the to-do item from the "all" observable collection. AllToDoItems.Remove(toDoForDelete); // Remove the to-do item from the data context. toDoDB.Items.DeleteOnSubmit(toDoForDelete); // Remove the to-do item from the appropriate category. switch (toDoForDelete.Category.Name) { case "Home": HomeToDoItems.Remove(toDoForDelete); break; case "Work": WorkToDoItems.Remove(toDoForDelete); break; case "Hobbies": HobbiesToDoItems.Remove(toDoForDelete); break; default: break; } // Save changes to the database. toDoDB.SubmitChanges(); }
// Add a to-do item to the database and collections. public void AddToDoItem(ToDoItem newToDoItem) { // Add a to-do item to the data context. toDoDB.Items.InsertOnSubmit(newToDoItem); // Save changes to the database. toDoDB.SubmitChanges(); // Add a to-do item to the "all" observable collection. AllToDoItems.Add(newToDoItem); // Add a to-do item to the appropriate filtered collection. switch (newToDoItem.Category.Name) { case "Home": HomeToDoItems.Add(newToDoItem); break; case "Work": WorkToDoItems.Add(newToDoItem); break; case "Hobbies": HobbiesToDoItems.Add(newToDoItem); break; default: break; } }
// Called during a remove operation private void detach_ToDo(ToDoItem toDo) { NotifyPropertyChanging("ToDoItem"); toDo.Category = null; }
// Called during an add operation private void attach_ToDo(ToDoItem toDo) { NotifyPropertyChanging("ToDoItem"); toDo.Category = this; }