private static void ExecutedDeleteTaskCommand(object sender, ExecutedRoutedEventArgs e) { UserTask task = e.Parameter as UserTask; string id = task.ID; TasksPeekContent _sender = sender as TasksPeekContent; foreach (TreeViewItem each in _sender.tasksTreeView.Items) { foreach (TreeViewItem t in each.Items) { if ((t.Header as UserTask).ID == id) { _sender.deleteTask(t, false); break; } } } }
private static void ExecutedTaskReorderCommand(object sender, ExecutedRoutedEventArgs e) { ItemReorderEventArgs args = (ItemReorderEventArgs)e.Parameter; TasksPeekContent _sender = (TasksPeekContent)sender; UserTask _peekTask = (UserTask)args.Item.Header; TreeViewItem tvItem = null; foreach (TreeViewItem parent in _sender.tasksTreeView.Items) { foreach (TreeViewItem child in parent.Items) { if (((DatabaseObject)child.Header).ID == _peekTask.ID) { tvItem = child; break; } } if (tvItem != null) { break; } } if (tvItem == null) { UserTask task = (UserTask)args.Item.Header; int newIndex = ((ItemsControl)args.Item.Parent).Items.IndexOf(args.Item); string header = "No Date"; if (task.DueDate != null) { header = TasksView.GetFriendlyName(task.DueDate.Value); } TreeViewItem group = new TreeViewItem() { Header = header }; _sender.AddTask(new UserTask(task), group, true, newIndex); } else { UserTask task = (UserTask)tvItem.Header; task.DueDate = _peekTask.DueDate; task.StartDate = _peekTask.StartDate; string header = "No Date"; if (task.DueDate != null) { header = TasksView.GetFriendlyName(task.DueDate.Value); } TreeViewItem group = new TreeViewItem(); group.Header = header; int origIndex = ((ItemsControl)tvItem.Parent).Items.IndexOf(tvItem); int newIndex = ((ItemsControl)args.Item.Parent).Items.IndexOf(args.Item); if (origIndex < newIndex && args.NewParent == args.OldParent && Settings.AnimationsEnabled) { newIndex++; } _sender.deleteTask(tvItem, false); _sender.AddTask(task, group, true, newIndex); if (task.IsOverdue && task.Status != UserTask.StatusPhase.Completed) { tvItem.Foreground = new SolidColorBrush(Color.FromArgb(255, 218, 17, 17)); } else { tvItem.Foreground = Brushes.Black; } } }