开发者

Printing in Silverlight 4

开发者 https://www.devze.com 2022-12-28 13:48 出处:网络
We have an application structured roughly like this: <Grid x:Name=\"LayoutRoot\"> <ScrollViewer>

We have an application structured roughly like this:

<Grid x:Name="LayoutRoot">
  <ScrollViewer>
<Canvas x:Name="canvas">
  <StackPanel> < Button /><Slider /><Button /></StackPanel>
  <custom:Blob />
  <custom:Blob />
  <custom:Blob />
</Canvas>
  </ScrollViewer>
</Grid>

Each Blob consists of 1 or more rectangles, lines, and text boxes; they are positioned anywhere on the canvas.

If I print the document using the LayoutRoot:

PrintDocument pd = new PrintDocument();
pd += (s, pe) => { pe.PageVisual = LayoutRoot; };
pd.Print("Blobs");

... it is like a print-screen -- the scrollbars, the sliders, the blobs that are visible -- are printed.

If I set PageVisual = canvas, nothing is printed.

How can I get all the blob objects, and just those objects, to print? Do I need to copy them i开发者_运维问答nto another container, and give that container to PageVisual? Can I use a ViewBox to make sure they all fit on one page?

Thanks for any pointers....


First idea that came to mind while reading your post was the size of your canvas that groups your Blob objects. So found some interesting fragments that might help you:

In addition to specifying the UIElement, you can get the physical size of the print area with the PrintPageEventArgs..::.PrintableArea property. If the UIElement exceeds the PrintableArea, the content will be clipped at the bounds of the PrintableArea. The dimensions of the printable area are in screen-based pixels.

and

You use the PrintPageEventArgs..::.HasMorePages property to print a document with multiple pages. The default for PrintPageEventArgs..::.HasMorePages is false, so it does not need to be set for one-page documents. However, if there are multiple pages to print, you set the PrintPageEventArgs..::.HasMorePages property to true to indicate that there are additional pages to print. You set PrintPageEventArgs..::.HasMorePages back to false in the PrintPage event handler, when the last page is being printed.

Documentation article


You can apply a scale tranform on the LayoutRoot before printing.

But I have run across a problem where LayoutRoot stays scaled down/up after printing. (Question asked here)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号