Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

Printing Issues with RenderTransform

$
0
0

We are getting very strange behavior when trying to print in Silverlight.  After extensive hair pulling we were able to narrow down the cause of the problem to a RotateTransform that exists in the control being printed.  When we comment out the rotate transform the printing works as expected, however, when the transform is in place, very unexpected scaling occurs, and we have no idea why it is being caused or even how to resolve it.  We are also not sure if the Silverlight print engine is capable of properly handling a RenderTransform.  We are hoping that someone may have experienced this issue and solved it, or can tell us what we might be doing wrong.  We have greatly simplified the code to show a simple example of how to reproduce the problem and the output that is generated.  Thanks.

Here is the XAML test code used to produce the unexpected behavior:

<UserControl x:Class="ResourceProfilingTool.MyPlotPerLaborCategoryReportView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             d:DesignHeight="900"
             d:DesignWidth="816"><Grid x:Name="LayoutRoot"
          Background="LightGray"><ItemsControl ItemsSource="ABCDEFGHIJKLMNOP"><ItemsControl.ItemTemplate><DataTemplate><Border Height="40"
                            BorderBrush="Black"
                            BorderThickness="1"
                            Margin="0"><Grid><TextBlock Text="B"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Center"
                                       Margin="0 20 0 0"
                                       FontSize="26"><TextBlock.RenderTransform><RotateTransform Angle="-45" /></TextBlock.RenderTransform></TextBlock><TextBlock Text="B"
                                       HorizontalAlignment="Left"
                                       VerticalAlignment="Center"
                                       Margin="0 20 0 0"
                                       FontSize="26"><TextBlock.RenderTransform><RotateTransform Angle="-45" /></TextBlock.RenderTransform></TextBlock><TextBlock Text="B"
                                       HorizontalAlignment="Right"
                                       VerticalAlignment="Center"
                                       Margin="0 20 20 0"
                                       FontSize="26"><TextBlock.RenderTransform><RotateTransform Angle="-45" /></TextBlock.RenderTransform></TextBlock></Grid></Border></DataTemplate></ItemsControl.ItemTemplate></ItemsControl></Grid></UserControl> 

Now, if we simply embed this UserControl into the visual tree we get the expected (correct output) as shown below:

Now if we try to print this UserControl using the following code below (i.e. the UserControl instance is passed in as the argument):

        void Print(UIElement document)
        {
            PrintDocument printer = new PrintDocument();
            printer.PrintPage +=
                (s, e) =>
                {
                    e.PageVisual = new Border() { Padding = new Thickness(48), Child = document };
                };
            printer.Print("Test");
        }

The following output is produced when printed (to a PDF here).  Notice that as each Item is rendered in the ItemsControl that they progressively get narrower and narrower.  From other testing we have done it appears that each item is being applied with an ever increasing scale transform that is shrinking the object. However, the code shows no such transform and debugging the code shows that no transform is being applied (i.e. it shows identity matrix) on the user control's RenderTransform property. We are struggling to prevent this from happening:


Viewing all articles
Browse latest Browse all 1083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>