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()
{
InitializeComponent();
_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;
LayoutRoot.Children.Add(_diagramControl);
#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;
}
else
{
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);
dtl.RefreshLayout();
}
SM
Sundar M
Syncfusion Team
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.
Regards,
Sundar M.