Leave and enter a Diagram with same Viewport

Hi!

I have a GoSilverlight-Diagram in a TabControl. I want to be able to leave the tab, enter it again and see the same viewport. The following code works normally fine:

<br />private Rect _CurrentViewport; <br />// Eventhandler for Diagram.Unloaded <br />private void OnDiagramUnloaded( object sender, RoutedEventArgs e ) <br />{ <br /> SaveGraphicalInformations(); // Saves the Location and IsExpandedTree of each Node <br /> _CurrentViewport = myDiagram.Panel.ViewportBounds; <br />} <br /> <br />// Eventhandler for Diagram.Loaded <br />private void OnDiagramLoaded( object sender, RoutedEventArgs e ) <br />{ <br /> UseGraphicalInformations(); // Sets the Location and IsExpandedTree of each Node <br /> if ( !_CurrentViewport.IsEmpty ) <br /> { <br /> myDiagram.Panel.Position = new Point( correctNewViewport.X, correctNewViewport.Y ); <br /> } <br />} <br />



Because the user has to be able to decide where the nodes should be positioned I use a DiagramLayout and Use-/SaveGraphicalInformation() which gets or sets the Location and IsTreeExpanded of each node.



This solution works fine as long as I don´t change IsTreeExpanded. If I use the my CollapseTree-Button, leave the tab and enter it again it shows a wrong viewport.



I appreciate any ideas why this solution doesn´t work or ideas to set the viewport correctly.



Thanks

Lukas

Which version of the DLL are you using? And you are targeting Silverlight 4, right? I’m assuming you are using Silverlight 4, because there are no Loaded and Unloaded events in Silverlight 3.

If you are using 1.1.3 (through 1.1.5), you can just set Diagram.UnloadingClearsPartManager to false. You probably don’t need to implement Loaded and Unloaded event handlers at all, because all of the Diagram state will be retained when the user changes tabs.

If you are using GoSilverlight 1.1.6 or later, it automatically treats that property as false if the Diagram is inside a TabControl. Again, probably no need for those event handlers.

Hi Walter!

Thanks a lot.

<br /><Diagram ... UnloadingClearsPartManager="False" Unloaded="OnDiagramUnloaded" Loaded="OnDiagramLoaded">... <br />

and

<br />private Rect _CurrentViewport; <br /> <br />// Eventhandler for Diagram.Unloaded <br />private void OnDiagramUnloaded( object sender, RoutedEventArgs e ) <br />{ <br /> _CurrentViewport = myDiagram.Panel.ViewportBounds; <br />} <br /> <br />// Eventhandler for Diagram.Loaded <br />private void OnDiagramLoaded( object sender, RoutedEventArgs e ) <br />{ <br /> if ( !_CurrentViewport.IsEmpty ) myDiagram.Panel.Position = new Point( correctNewViewport.X, correctNewViewport.Y ); <br />} <br />

works.



With UnloadingClearsPartManager=“False” it is not necessary to save/load the node-locations. The event-handler keeps the viewport correct. Exactly what I needed.



Thanks!

Lukas

Are you saying that you still need to save _CurrentViewport?

I would have thought that you wouldn’t need either event handler at all.

Hi Walter!

Yes. If I don´t use _CurrentViewport after switching tabs the new viewport has moved to the left.

I don´t know why it works like this, but it works for me.

Lukas



(If you think it is a bug I would have a look at DiagramPanel.Padding. The distance the viewport moves to the left is approx. similar to DiagramPanel.Padding.Left. Hope this helps!)