/// <summary> /// Adds the task to the selected list. This method is invoked by the AddCommand. /// </summary> public void AddTask() { // add the selected task to the collection of selected tasks TaskTreeNodeViewModel taskNodeVM = SelectedNode as TaskTreeNodeViewModel; TaskViewModel taskVM = new TaskViewModel(_taskData.GetTaskByTaskId(taskNodeVM.NodeId), _taskData); SelectedTasks.Add(taskVM); RemoveTaskFromTree(taskNodeVM, taskVM); // clear the selected node SelectedNode = null; }
void GongSolutions.Wpf.DragDrop.IDropTarget.Drop(DropInfo dropInfo) { if (dropInfo.Data is TaskViewModel) { // drop a task from the list view to the tree view TaskViewModel sourceTask = (TaskViewModel)dropInfo.Data; ((ListCollectionView)dropInfo.DragInfo.SourceCollection).Remove(sourceTask); AddTaskToTree(sourceTask); } else { // drop a task from the tree view to the list view TaskTreeNodeViewModel sourceTask = (TaskTreeNodeViewModel)dropInfo.Data; TaskViewModel taskVM = new TaskViewModel(_taskData.GetTaskByTaskId(sourceTask.NodeId), _taskData); RemoveTaskFromTree(sourceTask, taskVM); ((ListCollectionView)dropInfo.TargetCollection).AddNewItem(taskVM); ((ListCollectionView)dropInfo.TargetCollection).CommitNew(); } }
/// <summary> /// Remove the node and any empty ancestors from the tree /// </summary> void RemoveTaskFromTree(TaskTreeNodeViewModel taskNodeVM, TaskViewModel taskVM) { ITreeNodeContainerViewModel parent = taskNodeVM.Parent; if (parent != null) { _removedNodes.Add(taskVM, taskNodeVM); parent.ChildNodes.Remove(taskNodeVM); while (parent != null && parent.ChildNodes.Count == 0) { ITreeNodeContainerViewModel child = parent; parent = child.Parent; if (parent != null) { parent.ChildNodes.Remove(child); } } } }