public void RemoveCategory() { if (this.selectedCategory == null) { MessageBoxHelper.ShowWarning("请选择要删除的节点"); return; } if (MessageBoxHelper.ShowConfirm(string.Format("您确定要删除\"{0}\"?", this.selectedCategory.Name)) == MessageBoxResult.No) { return; } Category category = this.selectedCategory.Model; this.categoryClient.DeleteCategoryAsync(this.scope.ToString(), category.Id) .ExcuteOnUIThread( () => { Tree.PostorderTraverse(this.selectedCategory, (node) => { CategoryViewModel viewModel = node as CategoryViewModel; if (viewModel.Children != null && viewModel.Children.Count > 0) { for (int i = viewModel.Children.Count - 1; i >= 0; i--) { viewModel.RemoveChildAt(i); } } }); if (this.selectedCategory.Parent == null) { this.CategoryList.Remove(this.selectedCategory); } else { this.selectedCategory.Parent.RemoveChild(this.selectedCategory); } }, (ex) => { TaskHelper.HandleWebException(ex); }); }
public static void CleanupTree(ObservableCollection <TreeNodeModel> tree) { if (tree != null && tree.Count > 0) { Tree.PostorderTraverse(tree, (e) => { CategoryViewModel current = e as CategoryViewModel; if (current.Children != null && current.Children.Count > 0) { for (int i = current.Children.Count - 1; i >= 0; i--) { current.RemoveChildAt(i); } } }); tree.Clear(); } }