Hey Tony, more info on what I meant:

>> I believe this is happening because the bitmap does not render from a tab
>> that has not been made
>> visible prior to clicking Print.

Your suspicions are correct.  See 
http://msdn.microsoft.com/en-us/library/dd351483%28VS.95%29.aspx

"During the measure pass of layout. The value for the Template  property, if 
it has been set, will be expanded to provide the visual tree. The control is 
initially created without a visual tree, and the visual tree is cleared when 
the Template  property is set."


The key bit here: "... will be expanded to provide the visual tree.".

See also http://forums.silverlight.net/forums/t/184562.aspx


This is why I think you should just need to call Measure() and Arrange() on 
your additional (i.e. non visible) Tab Pages to expand their templates. You 
should be able to use the positional/width etc  values from your visible 
Tab.

Dan

--------------------------------------------------
From: <[email protected]>
Sent: Thursday, June 24, 2010 11:42 AM
To: "ozSilverlight" <[email protected]>
Subject: Re: Printing in Silverlight / Writing a bitmap that's not visible

> Hi Tony,
>
> In WPF, (and I believe it is meant to be similar in Silverlight) these 
> sorts
> of issues are usually fixed by coding a 2 pass layout update (i.e. calling
> Measure() and Arrange()) on these objects that are not-yet-clicked-on to 
> get
> them into the Visual Tree.
>
> Dan.
> --------------------------------------------------
> From: <[email protected]>
> Sent: Thursday, June 24, 2010 11:27 AM
> To: <[email protected]>
> Subject: Printing in Silverlight / Writing a bitmap that's not visible
>
>> 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
> 
_______________________________________________
ozsilverlight mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight

Reply via email to