protected override Size MeasureOverride(Size availableSize) { if (Children.Count == 0) { return(new Size(100, 20)); } Size szFinal = new Size(0, 0); string strRoot = Root; TreeCanvasNode tnRoot = this.FindName(strRoot) as TreeCanvasNode; foreach (UIElement uiel in InternalChildren) { uiel.Measure(availableSize); Size szThis = uiel.DesiredSize; if (szThis.Width > szFinal.Width || szThis.Height > szFinal.Height) { szFinal = new Size( Math.Max(szThis.Width, szFinal.Width), Math.Max(szThis.Height, szFinal.Height)); } } if (tnRoot != null) { SetParents(tnRoot); _ltd = new LayeredTreeDraw(tnRoot, HorizontalBuffer, HorizontalBufferSubtree, VerticalBuffer, VerticalJustification.top); _ltd.LayoutTree(); szFinal = new Size(_ltd.PxOverallWidth, _ltd.PxOverallHeight); } return(szFinal); }
/// <summary> /// Refresh tree control /// </summary> public void RefreshTree() { //Auto enable scroll for new content size _ltd = new LayeredTreeDraw(m_RootNode, 17.5, 17.5, 17.5, VerticalJustification.top); _ltd.LayoutTree(); this.AutoScrollMinSize = new Size((int)_ltd.PxOverallWidth + this.Margin.Left + this.Margin.Right, (int)_ltd.PxOverallHeight + this.Margin.Top + this.Margin.Bottom); Invalidate(); }
static public void CollapsePropertyChange(DependencyObject o, DependencyPropertyChangedEventArgs e) { TreeCanvasNode tn = o as TreeCanvasNode; if (tn != null && tn.Collapsible) { bool fCollapsed = ((bool)e.NewValue); foreach (TreeCanvasNode tnCur in LayeredTreeDraw.VisibleDescendants <TreeCanvasNode>(tn)) { tnCur.Visibility = fCollapsed ? Visibility.Hidden : Visibility.Visible; } } }
/// <summary> /// Prepare for Tree node draw. /// </summary> /// <param name="gpRoot"></param> /// <param name="funNodeValue">delegate for callback for retrieve GPNode string representation</param> public void DrawTreeExpression(Node gpRoot, NodeValue funNodeValue, IParameters param = null, NodeBackground funNodeBackground = null) { Clear(); parameters = param; //define callbacks for _funNodeValueCallback = funNodeValue; _funNodeBackgroundCallback = funNodeBackground; //Collection holds tree nodes Queue <Node> dataTree = new Queue <Node>(); Queue <TreeNodeDrawer> ctrls = new Queue <TreeNodeDrawer>(); //current node Node node = null; TreeNodeDrawer treeCtrl = null; treeCtrl = AddNode(gpRoot.Value, gpRoot.marked, null); ctrls.Enqueue(treeCtrl); dataTree.Enqueue(gpRoot); while (dataTree.Count > 0) { //get next node node = dataTree.Dequeue(); treeCtrl = ctrls.Dequeue(); if (node.Children != null) { for (int i = 0; i < node.Children.Length; i++) { var tn = AddNode(node.Children[i].Value, node.Children[i].marked, treeCtrl); dataTree.Enqueue(node.Children[i]); ctrls.Enqueue(tn); } } } _ltd = new LayeredTreeDraw(m_RootNode, 17.5, 17.5, 17.5, VerticalJustification.top); _ltd.LayoutTree(); //Auto enable scroll for new content size this.AutoScrollMinSize = new Size((int)_ltd.PxOverallWidth + this.Margin.Left + this.Margin.Right, (int)_ltd.PxOverallHeight + this.Margin.Top + this.Margin.Bottom); Invalidate(); }
protected override Size MeasureOverride(Size availableSize) { if (Children.Count == 0) { return new Size(100, 20); } Size szFinal = new Size(0, 0); string strRoot = Root; TreeNode tnRoot = this.FindName(strRoot) as TreeNode; foreach (UIElement uiel in InternalChildren) { uiel.Measure(availableSize); Size szThis = uiel.DesiredSize; if (szThis.Width > szFinal.Width || szThis.Height > szFinal.Height) { szFinal = new Size( Math.Max(szThis.Width, szFinal.Width), Math.Max(szThis.Height, szFinal.Height)); } } if (tnRoot != null) { SetParents(tnRoot); _ltd = new LayeredTreeDraw(tnRoot, HorizontalBuffer, HorizontalBufferSubtree, VerticalBuffer, VerticalJustification.top); _ltd.LayoutTree(); szFinal = new Size(_ltd.PxOverallWidth, _ltd.PxOverallHeight); } return szFinal; }