Posted by: MarkWPF
From a previous post of mine, you can see how to easily increase the size of a WPF element in order to print it.
That’s not much use though as you are still only hard coding the sizing.
What would be better is to use the height and width of the paper that has been selected.
Lo and behold, thats easy to do, using the PrintDialog class itself.
One further wrinkle is that you need to make sure that the actual element is resized, and you do that by telling it to resize itself.
Say you have an instance of PrintDialog called prtDlg:
Size pageSize = new Size(prtDlg.PrintableAreaWidth -30, prtDlg.PrintableAreaHeight – 30);
grd.Arrange(new Rect(15, 15, pageSize.Width, pageSize.Height));
prtDlg.PrintVisual(grd, “My grid”);
Where grd is a Grid control containing a number of other elements