PrintPreview of diagram on click of button

Hi,

I am displaying Print Preview of my diagram with reference of the code present in GoWPFDemo4 solution.I am creating new instance of the class on load of my diagram using the below code:
new PreviewingPrintManager().Init(diagram)
Here diagram is my diagram for whose i want to display print preview.In the Init method i am binding a method "UpdatePrintGrid" which does the calculation of displaying print preview to diagram' panel DiagramBoundChanged event:
this.Diagram.Panel.DiagramBoundsChanged += (s, e) => UpdatePrintGrid();
Using this i am able to see the print preview in the diagram but only in change of diagram bound.
I want to display that grid pattern of print preview on click of my button along with diagram bound change also, even though i dont change the bound of diagram.
The below "gp" object comes as null when the above method "UpdatePrintGrid" gets called on click of my button.But it gets the value on diagram bound change as it gets the element "GridPattern". Here "printGrid" is a temporary Node.
GridPattern gp = (GridPattern)printGrid.FindNamedDescendant("GridPattern");
Any help would be great.
Thanks,
Abdeali

Did you want to have your button toggle the visibility of the print grid? If so, you just need to toggle the value of PreviewingPrintManager.IsPreviewEnabled. I hope that you are only creating a PreviewingPrintManager once – I don’t know what happens if you construct more than one for a Diagram.

If you are creating the PreviewingPrintManager on demand, I suppose you can just call UpdatePrintGrid() directly. That sample code was designed so that the PreviewingPrintManager is constructed and initialized only once, along with the rest of the Diagram initialization. Loading any Model would of course cause the diagram bounds to change.

As the comments in that sample discuss, the assumption is that there is a GridPattern object named “GridPattern” that is within the visual tree of the print grid Node. If you are getting null at that point, I cannot explain it except that you just didn’t define your Node in the same way.

Thanks a lot for the helpful suggestion.I was creating the Node at runtime but now i have added the same in xaml itself so now everytime i am able to get the gridpattern!

Abdeali