Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Print/Preview diagram moves arrows (Read 3085 times)
matt.s
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 56
Joined: Apr 3rd, 2008
Print/Preview diagram moves arrows
Feb 20th, 2009 at 6:03pm
Print Post  
Hi,

I have a simple diagram layout with two nodes, and an arrow between the nodes.

When I print the diagram using DocumentPaginator everything is fine.

However, if I save the diagram to XML and then reload it to a new diagram object prior to printing the diagram, the arrows move to a different position.

The code I am using to save/load to xml is as follows;

Code
Select All
            XmlDocument xmlDoc = new XmlDocument();
            diagram.SaveToXml(xmlDoc);

            Diagram copyDiagram = new Diagram();
            copyDiagram.LoadFromXml(xmlDoc);
 



The code I am using to preview the diagram is as follows;

Code
Select All
            MemoryStream ms = new MemoryStream();
            Package pkg = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
            string pack = "pack://temp.xps";
            PackageStore.AddPackage(new Uri(pack), pkg);
            XpsDocument doc = new XpsDocument(pkg, CompressionOption.NotCompressed, pack);
            XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
            rsm.SaveAsXaml(m_Diagram.DocumentPaginator);
            docViewer.Document = doc.GetFixedDocumentSequence(); ;
 



Am I doing something wrong?

Thanks in advance
Matt


  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Print/Preview diagram moves arrows
Reply #1 - Feb 20th, 2009 at 6:42pm
Print Post  
Hi,

Are you running the preview code immediately after loading? It might be that the WPF arrange phase hasn't completed when the paginator get the VisualBrush used for printing. You could try running the UpdateLayout method before printing.

Stoyan
  
Back to top
 
IP Logged
 
matt.s
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 56
Joined: Apr 3rd, 2008
Re: Print/Preview diagram moves arrows
Reply #2 - Feb 23rd, 2009 at 8:59am
Print Post  
Hi Stoyan,

That's correct I load the diagram and immediately load it into the previewer.

I have tried UpdateLayout() and also InvalidateVisual() but neither of them change the output.

Any other suggestions you have would be greatly appreciated!

Matt
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Print/Preview diagram moves arrows
Reply #3 - Feb 23rd, 2009 at 11:22am
Print Post  
Hi Matt,

With some trial and error we found the following method to make it work correctly:

private void OnFilePrintPreview(object sender, RoutedEventArgs e)
{
     XmlDocument xmlDoc = new XmlDocument();
     diagram.SaveToXml(xmlDoc);

     Diagram copyDiagram = new Diagram();
     copyDiagram.LoadFromXml(xmlDoc);
     sv.Content = copyDiagram;
     copyDiagram.UpdateLayout();
     DiagramPaginator dp = (DiagramPaginator)copyDiagram.DocumentPaginator;
     sv.Content = diagram;
     // etc ...
}

where 'sv' is the original ScrollViewer container of diagram. Our guess is that UpdateLayout works correctly only for controls that are part of the visual tree, so you must add copyDiagram at least temporarily as a child in the UI tree.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
matt.s
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 56
Joined: Apr 3rd, 2008
Re: Print/Preview diagram moves arrows
Reply #4 - Feb 23rd, 2009 at 2:27pm
Print Post  
Hi Stoyan,

That does the trick - thanks.

Matt
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint