May try calling it on a dispatcher callback...
On Thu, Jun 24, 2010 at 11:27 AM, <[email protected]> wrote:
> Hi all,
>
> We have moved to Silverlight 4 due to the printing capability. I have been
> working on the best way
> to enable printing in my application. I have settled on writing page
> components to Bitmaps, then
> slotting those bitmaps into a page template control (printTemplate) and
> printing that. It's all been
> working fine except that now I have hit a problem.
>
> I have a tab control. The tab control has a number of tabs. When I click
> the Print button that I
> have added to the page, it works it's way through all the tabs and prints a
> report that contains the
> content. Now, it works fine if I have clicked on all the tabs before-hand,
> however if I do not click
> the tabs beforehand, then the content of those tabs will not get generated
> within the report.
>
> However, if I set the element directly into e.PageVisual, then the element
> will display.
>
> I believe this is happening because the bitmap does not render from a tab
> that has not been made
> visible prior to clicking Print.
>
> I have attached some code below and it is still a work in progress. Most of
> my printing involves
> Landscape orientation, and if I set it to Portrait, or set e.PageLayout =
> elementToPrint, then the
> element will clip, which is undesireable.
>
> How can I get an element to render inside a bitmap without the element
> needing to be visible first?
>
> Regards,
> Tony
>
> private void PrintPage(FrameworkElement elementToPrint, PrintPageEventArgs
> e, string
> headingTitle, string footerTitle, PageOrientation orientation =
> PageOrientation.Portrait)
> {
> PrintTemplateControl printTemplate = new PrintTemplateControl();
> printTemplate.SetHeaderAndFooterText(headingTitle, footerTitle);
>
> double printableHeight = e.PrintableArea.Height -
> printTemplate.HeightOffset;
> int contentWidth = Convert.ToInt32(elementToPrint.ActualWidth);
> int contentHeight = Convert.ToInt32(elementToPrint.ActualHeight);
> WriteableBitmap bitmap;
> if (orientation == PageOrientation.Portrait)
> {
> bitmap = new WriteableBitmap(contentWidth, contentHeight);
> bitmap.Render(elementToPrint,new TranslateTransform());
> }
> else
> {
> bitmap = new WriteableBitmap(contentHeight, contentWidth);
> TransformGroup transformGroup = new TransformGroup();
> RotateTransform rotateTransform = new RotateTransform();
> rotateTransform.Angle = 90;
> transformGroup.Children.Add(rotateTransform);
> TranslateTransform moveTransform = new TranslateTransform();
> moveTransform.X = contentHeight;
> transformGroup.Children.Add(moveTransform);
> ScaleTransform scaleTransform = new ScaleTransform();
> double ratioOfImageToPrintArea = 1;
> if (elementToPrint.ActualWidth > printableHeight)
> ratioOfImageToPrintArea = printableHeight /
> elementToPrint.ActualWidth;
> scaleTransform.ScaleX = ratioOfImageToPrintArea;
> scaleTransform.ScaleY = ratioOfImageToPrintArea;
> transformGroup.Children.Add(scaleTransform);
> bitmap.Render(elementToPrint, transformGroup);
> }
> bitmap.Invalidate();
>
> Image printImageSource = new Image();
> printImageSource.Source = bitmap;
> printImageSource.Width = bitmap.PixelWidth;
> printImageSource.Height = bitmap.PixelHeight;
>
> printTemplate.AddChildren(printImageSource);
>
> e.PageVisual = printTemplate;
> }
>
>
> _______________________________________________
> ozsilverlight mailing list
> [email protected]
> http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight
>
_______________________________________________
ozsilverlight mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight