Hi,
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!