Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1925
xamDiagram nodes alignment for newly created objects
posted

Referring to http://es.infragistics.com/samples/wpf/diagram/binding-nodes-with-objects

Can you please suggest recommended way of aligning new nodes if a child node is created on fly. I have set TreeDiagramLayout's NodeFlowDirection to "Below" but when a new object is added in viewmodel at run time it goes to top left corner of diagram.

Ideally starting from parent, I would like nodes to be center aligned and newly created to be below parent node.

Parents
  • 29065
    Offline posted

    Hello Abs,

    The diagram layout is applied only initially to the diagram. If the items are added/removed later (eg. view model collection), the layout is not automatically applied. In order to rearrange the nodes at a later stage, call the RefreshLayout method directly on the XamDiagram.

    eg.

    mainWindow.Diagram.RefreshLayout();

    For more details please visit:
    http://es.infragistics.com/help/wpf/xamdiagram-configuring-the-layout

    If you require a custom position you can use the diagram's items collection changed event to do so:

    eg.

       private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            {
                FamilyTreeViewModel vm = this.Diagram.DataContext as FamilyTreeViewModel;

                if (e.NewStartingIndex >= vm.FamilyTree.Count)
                {
                    if (e.NewItems[0] is DiagramNode)
                    {

                        DiagramNode newlyAdded = e.NewItems[0] as DiagramNode;
       
                        newlyAdded.Position = new Point(50, 50);
                    }
                   
                }
            }

    Let me know if you have any questions regarding this matter.

Reply Children