Hi
This is for GoXam Silverlight 2.0.2.5
This post contains two questions:
-
What is the proper way to change/swap-out a Diagram’s current layout at runtime?
-
When swapping out the layout of a Diagram that contains groups/sub-graphs, the groups don’t seem to layout correctly.
-
What is the proper way to change/swap-out a Diagram’s current layout at runtime?
I have a requirement to change an existing Diagram’s layout at runtime so that the user can decide for themselves which layout they wish to use for building or modifying a diagram. For eg. if the current Layout for a Diagram is a DiagramLayout object, I might swap it out with a TreeLayout object. Currently, I’m changing layout using the following code:
Diagram.Layout = _layoutProvider.GetDiagramLayout(layoutType.Value);
Diagram.StartTransaction(“LayoutChanged”);
Diagram.PartManager.RebuildLinkElements();
Diagram.LayoutManager.LayoutDiagram();
Diagram.CommitTransaction(“LayoutChanged”);
where _layoutProvider is an object that constructs a diagram layout based on some user input. My Diagram is using a GraphLinksModel and I find that I need to call Diagram.PartManager.RebuildLinkElements() when switching back and forth between layouts or else the links don’t behave as expected.
My question is, is the code above the proper way to swap out a Diagram’s Layout at runtime?
- When swapping out the layout of a Diagram that contains groups/sub-graphs, the groups don’t seem to layout correctly.
Imagine I have a diagram that looks like the following:
The Diagram’s initial layout is a DiagramLayout object.
I then swap out the layout with a TreeLayout object with an Angle of 0 degrees, producing a tree layout of left-to-right:
This all works as expected. However, imagine I have a diagram containing a group as follows:
I then swap out the layout with a TreeLayout as before. However, this produces an unexpected result:
I would expect the layout to look as follows:
Am I doing something wrong?
That DataTemplate for the Group is as follows:
<go:SpotPanel go:Node.LocationElementName="GroupPanel" go:Node.Location="{Binding Data.Location, Mode=TwoWay}" go:Node.LinkableTo="False" go:Node.LinkableFrom="False" go:Node.LinkableSelfNode="False" go:Node.LinkableDuplicates="False" go:Part.SelectionAdorned="true" go:Part.SelectionElementName="GroupBorder" go:Part.LayerName="{Binding Data.LayerID}" go:Part.LayoutId="{Binding Data.LayoutID}" go:Group.IsSubGraphExpanded="{Binding Data.IsSubGraphExpanded}" go:Node.PortId="" go:Part.Rotatable="False" go:Part.Resizable="False" >
<Border x:Name="GroupBorder"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="5"
Padding="6"
>
<go:Group.Layout>
<go:DiagramLayout Conditions="All" />
</go:Group.Layout>
<StackPanel>
<TextBlock>
<Run Text="{Binding Data.Text}" />(<Run Text="{Binding Data.Location}" />)
</TextBlock>
<go:GroupPanel x:Name="GroupPanel" go:Node.LinkableFrom="False" go:Node.LinkableTo="False"/>
</StackPanel>
</Border>
<Rectangle Fill="Transparent" Width="6" Height="6"
go:SpotPanel.Spot="MiddleLeft" go:SpotPanel.Alignment="MiddleLeft"
go:Node.PortId="" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
go:Node.LinkableDuplicates="False" />
<Rectangle Fill="Transparent" Width="6" Height="6"
go:SpotPanel.Spot="MiddleTop" go:SpotPanel.Alignment="MiddleTop"
go:Node.PortId="" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
go:Node.LinkableDuplicates="False" />
<Rectangle Fill="Transparent" Width="6" Height="6"
go:SpotPanel.Spot="MiddleRight" go:SpotPanel.Alignment="MiddleRight"
go:Node.PortId="" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
go:Node.LinkableDuplicates="False" />
<Rectangle Fill="Transparent" Width="6" Height="6"
go:SpotPanel.Spot="MiddleBottom" go:SpotPanel.Alignment="MiddleBottom"
go:Node.PortId="" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
go:Node.LinkableDuplicates="False" />
</go:SpotPanel>
</DataTemplate>
Thanks
Justin