Nodes Alignment

Hi,

Can we align child nodes either vertically or horizontally as desired. Here is the scenario:
I select a node and it has 7 children aligned horizontally. Now when I right click on the selected parent node and click on one of the menu items saying “Align Vertically”. An all children should then align vertically. Is it possible to achieve the same in GoSilverlight??

Thanks in advance!!!

Sure. I assume you already know how to create context menus, since that is the same for all FrameworkElements and not specific to GoXam.

Your commands can just position the nodes where you want.

private void MenuItem_Click(object sender, RoutedEventArgs e) {
  var partdata = ((FrameworkElement)sender).DataContext as PartManager.PartBinding;
  if (partdata != null && partdata.Node != null) {
    Node parent = partdata.Node;
    parent.Diagram.StartTransaction("align vertically");
    double x = parent.ActualBounds.Right + 10;
    double y = parent.ActualBounds.Bottom + 10;
    foreach (Node child in partdata.Node.NodesOutOf) {
      child.Position = new Point(x, y);
      y += child.ActualBounds.Height + 10;
    }
    parent.Diagram.CommitTransaction("align vertically");
  }
}

Caution: I haven’t even tried to compile this code, so pardon me if I made any mistakes.

Hi Walter,

Thanks for replying but the solution didn’t help me. It just respositioned the nodes. What I wished was to reallign them. I wish a node or part has some property like Alignment so that I could realign the child nodes as and when needed.

Help me out sir!!

I’m sorry, but I don’t understand what you are asking for.

But you ought to be able to adapt the code I wrote, above, for your own purposes.

Ya I used the code you wrote above. But what I want is something like this:
I have two nodes named “Alphabets” and “Digits”. Under “Alphabets” I have 5 child nodes (A, B, C, D, E) and similarly a few digits under Digits node. Both parent nodes have their children aligned horizontally. Now due to lack of space my two/three child nodes that are under “Digits” Node are out of visible area. So what I have decided is to align Alphabets children Vertically, so that all come into Visible area. After alignment resultant image will be something like this: Alphabets children are aligned horizontally while digits children are vertically aligned.

Now this is what I want to achieve. I hope now you got my point. :)