private void appBarOkButton_Click(object sender, EventArgs e) { if (newTaskNameTextBox.Text.Length > 0) { // Create a new to-do item. To_Do_Item newToDoItem = new To_Do_Item { ItemName = newTaskNameTextBox.Text, Category = (To_Do_Category)categoriesListPicker.SelectedItem, Password = Password_TextBox.Password, Description = Description_TextBox.Text }; App.ViewModel.DeleteToDoItem(newToDoItem.ItemName,newToDoItem.Category); // Add the item to the ViewModel. App.ViewModel.AddToDoItem(newToDoItem); // Return to the main page. if (NavigationService.CanGoBack) { NavigationService.GoBack(); } } }
/// <summary> /// delete an item . /// </summary> /// <param name="DeletableItem"> item that is to b deleted .</param> public void DeleteToDoItem(To_Do_Item DeletableItem) { if (DeletableItem != null) { // first do for all the superlistItems.Remove(DeletableItem); // remove from the linque thing . toDo_DB.Items.DeleteOnSubmit(DeletableItem); // remove item catagory wise . switch (DeletableItem.Category.Name) { case "Personal": PersonalToDoItems.Remove(DeletableItem); break; case "Office": OfficeToDoItems.Remove(DeletableItem); break; case "Misc": MiscToDoItems.Remove(DeletableItem); break; default: break; } // Save changes to the database. toDo_DB.SubmitChanges(); } }
// add the item both db and collection . public void AddToDoItem(To_Do_Item newToDoItem) { // Add item to the data context, of the linque class . toDo_DB.Items.InsertOnSubmit(newToDoItem); // Save changes to the database. toDo_DB.SubmitChanges(); //collection of items of all the items in the app . superlistItems.Add(newToDoItem); // put the item to the approprite , catagory . switch (newToDoItem.Category.Name) { case "Personal": PersonalToDoItems.Add(newToDoItem); break; case "Office": OfficeToDoItems.Add(newToDoItem); break; case "Misc": MiscToDoItems.Add(newToDoItem); break; default: break; } }
// remove operation private void detach_ToDo(To_Do_Item toDo) { NotifyPropertyChanging("ToDoItem"); toDo.Category = null; }
// add operation private void attach_ToDo(To_Do_Item toDo) { NotifyPropertyChanging("ToDoItem"); toDo.Category = this; }
private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e) { // Cast the parameter as a textBlock. var textBlock = sender as TextBlock; if (textBlock != null) { // Get a handle for the to-do item bound to the textBlock toDoForEdit = textBlock.DataContext as To_Do_Item; //if (!string.IsNullOrEmpty(toDoForEdit.Password)) //{ // NavigationService.Navigate(new Uri("/View/PasswordPage.xaml?Password="******"/View/NewTaskPage.xaml?selectedItem=" + (toDoForEdit.ToDoItemId.ToString()), UriKind.Relative)); //} } //// Put the focus back to the main page. //this.Focus(); }