Hello,
I would like to print the xamNetworkNode. I do not want to use PrintVisual. Is there anyway i could create a flow document and print that?
Thanks
Rohit
Hi Rohit,
I've looked into your requirements and I believe you should be able to use a FlowDocument where you can embed the XamNetworkNode control and then print the flow document with the PrintDialog.PrintDocument method. In order to embed the XamNetworkNode within a FlowDocument you will need to contain it within a BlockUIContainer.
I tried to create the flow document as you suggested:
FlowDocument
fDoc = new FlowDocument();
BlockUIContainer bContainer = new BlockUIContainer();
XamNetworkNode Temp = new XamNetworkNode();
Temp.NodeDistance = InNodeDistance;
Temp.SelectionType =
NetworkNodeSelectionType.Single;
Temp.ItemsSource = NetworkNodes;
bContainer.Child = Temp;
fDoc.Blocks.Add(bContainer);
For printing i used steps in the following link:
http://roecode.wordpress.com/2007/12/21/using-flowdocument-xaml-to-print-xps-documents/
It printed a blank page. Could you please tell me what am i doing wrong here?
Your code looks fine but you are missing some things. You are instantiating a XamNetworkNode control here and setting the ItemsSource but you also need to provide a NetworkNodeNodeLayout to the XamNetworkNode.GlobalNodeLayouts collection. This lets the control know how to read the data in the ItemsSource.
Another issue is the XamNetworkNode needs to have been rendered at least once so they nodes are created. A simple approach for this would be to have XamNetworkNode control already part of your application but hidden if you don't want to see it. You can then provide this control to the FlowDocument. Make sure you remove the network node control from it's container or an error will be thrown.
I've attached a sample application that demonstrates all of this. Let me know if you have any questions on it.
Let me know if you have any further questions regarding this matter.
Hi,
Thank you for the print sample.
I am able to print only the visible portion of the map.
How can we print the complete map? I mean the whole network map even if the nodes are not in view.
Prasad
Hi Prasad,
That is a lot of nodes and they definitely will not fit on one page. Unfortunately, like I said previously, the XamNetworkNode control does not have something like pagination implemented so it won't automatically know that it has to render onto a different page.
The only thing I can suggest is to maybe try breaking down the node map into smaller sections and then rendering each section to an image. You can then add the image to it's own page in the FlowDocument. I think for this you will need to create a custom paginator that will let you control what visuals go into each page. You can break up the node map into smaller sections by adjusting the WindowRect property. The WorldRect property is a rectangle that defines the entire area occupied by the node map. The WindowRect property designates what portion of the WorldRect is visible. So if you size the WindowRect appropriately you can programmatically move it around and render out an image of what the control sees.
This will work out for smaller maps of <50 nodes but if we have a map of >500 nodes, then the scale to fit and print will not give any details of the nodes in the map, at least the labels on the node are not visible. A map of >500 nodes if scaled to fit, the nodes will appear as tiny small shapes with out any details as attached in the sample snapshot. So is there any other possibility that we can print the parts of the map into different pages setting zoom level to 100% ?
Thanks,
If you are zooming in and then trying to print the whole network node, that isn't really going to work. You would have to increase the width and height of the XamNetworkNode control so that when you print it, it uses that size. Then you run into the issue where it may not fully fit on one page. There is no pagination with this control so it will try to render the whole thing on one page. If the control is made too big then it will be cutoff when you print it.
About the only thing I can suggest is that you set the Width and Height to the size you want it and then call ScaleToFit(). This will scale the nodes so they are all in view. Once they are all in view you can try printing it.