Userdefined margins in WPF printing

Posted by MTR on Stack Overflow See other posts from Stack Overflow or by MTR
Published on 2011-03-01T07:22:33Z Indexed on 2011/03/01 7:24 UTC
Read the original article Hit count: 211

Filed under:
|
|

Most printing samples for WPF go like this:

        PrintDialog dialog = new PrintDialog();
        if (dialog.ShowDialog() == true)
        {
           StackPanel myPanel = new StackPanel();
           myPanel.Margin = new Thickness(15);
           Image myImage = new Image();
           myImage.Width = dialog.PrintableAreaWidth;
           myImage.Stretch = Stretch.Uniform;
           myImage.Source = new BitmapImage(new Uri("pack://application:,,,/Images/picture.bmp"));
           myPanel.Children.Add(myImage);
           myPanel.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
           myPanel.Arrange(new Rect(new Point(0, 0), myPanel.DesiredSize));
           dialog.PrintVisual(myPanel, "A Great Image.");
        }

What I don't like about this is, that they always set the margin to a fixed value. But in PrintDialog the user has the option to choose a individual margin that no sample cares about. If the user now selects a margin that is larger as the fixed margin set by program, the printout is truncated. Is there a way to get the user selected margin value from PrintDialog?

TIA Michael

© Stack Overflow or respective owner

Related posts about wpf

Related posts about printing