Search code examples
c#wpfxamlprintingprintdialog

WPF: UIElement gone when printed


I have a very simple WPF XAML code:

<Grid Name="MainGrid" Margin = "20 0 20 0">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="auto"/>
    </Grid.RowDefinitions>

    <ScrollViewer>
        <StackPanel Name="RowsCont" Orientation="Vertical"/>
    </ScrollViewer>

    <Border Grid.Row="1" Background="#E9E9E9">
        <Border.Effect>
            <DropShadowEffect BlurRadius="10" ShadowDepth="1" Direction="90" Opacity=".5"/>
        </Border.Effect>
        <StackPanel Grid.Column="0" Orientation="Vertical" HorizontalAlignment="Left" Margin="5">
            <TextBlock Text="ORDERNUM:" FontSize="12" Foreground="Black" FontFamily="Bahnschrift" Margin="8 2 0 0"/>
            <TextBlock Name="OrderNumBlk" Text="Nazy-001" FontSize="20" Foreground="Black" FontFamily="Consolas" Margin="8 0 0 0" FontWeight="ExtraBold"/>
        </StackPanel>
    </Border>
</Grid>

Every thing shows up when i open the window up. The 'MainGrid' element is passed to PrintDialog's PrintVisual() method. Here's backend:

PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
printDlg.PrintVisual(MainGrid, "WPF Print");

Problem occurs when i actually print it down. 'Border' placed in the Grid.Row 1, just simply disappears.

I have no clue how could this even happen. Please help me figure that one out.

Thanks in advance.


Solution

  • Did not understand why it happened, but, somehow i disable 'Shadow Effect' and everything worked well.