private void RebuildNavigation(bool recreate) { using (FlagManager.UseFlag("BuildingNavTree")) { if (ProjectManager.IsProjectOpen) { var selectedNodeIDs = ProjectTreeView.SelectedObjects .OfType <ProjectTreeNode>().Select(x => x.NodeID).ToList(); selectedNodeIDs.RemoveAll(x => string.IsNullOrEmpty(x)); var expandedNodeIDs = ProjectTreeView.ExpandedObjects .OfType <ProjectTreeNode>().Select(x => x.NodeID).ToList(); expandedNodeIDs.RemoveAll(x => string.IsNullOrEmpty(x)); ProjectTreeView.ExpandedObjects = Enumerable.Empty <ProjectTreeNode>(); if (recreate) { ProjectTreeView.ClearObjects(); ProjectManager.RebuildNavigationTree(); ProjectTreeView.AddObjects(ProjectManager.NavigationTreeNodes.ToList()); foreach (ProjectCollectionNode node in ProjectTreeView.Roots) { node.Manager = ProjectManager; ProjectTreeView.Expand(node); } } else { foreach (ProjectTreeNode node in ProjectTreeView.Roots) { ProjectTreeView.RemoveObjects(node.GetChildHierarchy().ToList()); node.InvalidateChildrens(); ProjectTreeView.UpdateObject(node); } } //ProjectTreeView.TreeModel. ExpandNodes(ProjectTreeView.Roots, expandedNodeIDs); if (selectedNodeIDs.Any()) { SetSelectedNodeIDs(selectedNodeIDs); } } else { ProjectTreeView.ClearObjects(); } FilterNavigation(); } }