We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Centering the root node?

Thread ID:





97375 Nov 22,2010 06:05 PM UTC Nov 24,2010 01:35 PM UTC Silverlight 1
Tags: Diagram
Brad Lefferdink
Asked On November 22, 2010 06:05 PM UTC

Is there a way to have the root node of a DirectedTree auto center? For eaxample, when I do a Top-bottom layout, unless I manually set the resulting DiagramView.Bounds (or in code after initial load of page), the root node gets drawn at 0,0 and the diagram only scrolls to the right if necessary.

Is something like the following the only solution? (see MainPage_Loaded event handler):

public MainPage2()

_diagramControl = new Syncfusion.Windows.Diagram.DiagramControl();
_diagramControl.IsSymbolPaletteEnabled = false;
_diagramControl.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
_diagramControl.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

_diagramView = new DiagramView();
//_diagramView.Bounds = new Thickness(0, 0, 450, 10);
_diagramView.IsPageEditable = false;
_diagramControl.View = _diagramView;

_diagramModel = new DiagramModel();
_diagramModel.VerticalSpacing = 50;
_diagramModel.HorizontalSpacing = 30;
_diagramModel.SpaceBetweenSubTrees = 50;
_diagramModel.LayoutType = LayoutType.DirectedTreeLayout;
_diagramModel.Orientation = TreeOrientation.TopBottom;
_diagramControl.Model = _diagramModel;


#region For Testing
//Omitted code...
#endregion For Testing

(_diagramModel.Connections[_diagramModel.Connections.Count - 1] as LineConnector).Loaded += new RoutedEventHandler(MainPage_Loaded);

void MainPage_Loaded(object sender, RoutedEventArgs e)
DirectedTreeLayout dtl = new DirectedTreeLayout(_diagramModel, _diagramView);
//dtl.RefreshLayout(); //StartNodeArrangement();

double leftMost = 0;
double rightMost = 0;

foreach (Node node in _diagramModel.Nodes)
if (node.Equals(_diagramModel.Nodes[0] as Node))
leftMost = node.OffsetX;
rightMost = node.OffsetX + node.Width;
if (node.Visibility == System.Windows.Visibility.Visible)
if (node.OffsetX < leftMost)
leftMost = node.OffsetX;

if ((node.OffsetX + node.Width) > rightMost)
rightMost = node.OffsetX + node.Width;

//_diagramView.Bounds = new Thickness(0, 0, ((rightMost - leftMost) / 2) - ((_diagramModel.Nodes[0] as Node).Width / 2), 0);
_diagramView.Bounds = new Thickness(0, 0, ((rightMost - leftMost) + 20), 0);



Sundar M [Syncfusion]
Replied On November 24, 2010 01:35 PM UTC

Hi Brad,

Regarding directed tree layout’s root node position, in our 8.3v and older version releases, by default the root node of a directed tree layout is placed at 0,0. However in our currently released 8.4 version, the default position of the root node is placed at the center of the DiagramPage.

Please let us know if you have any queries.

Sundar M.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon