0
votes

I have two Pages used for printing.

1) PagePrinting.xaml
2) FormattedPage.xaml

in PagePrinting.xaml , I used the code below to reference the FormattedPage.xaml

FrameworkElement page1;
page1 = new FormattedPage();
CanvasPrintContainer.Children.Add(page1);

The problem:

  • The txtBlkDatePrint is blank when it is shown in PagePrinting.xaml

What I need to do?


in CodeBehind of FormattedPage.xaml :

 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            txtBlkDatePrint.Text = DateTime.Today.ToString("d");
        }

FormattedPage.xaml:

< StackPanel x:Name="header" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,0,0" Grid.Row="0" Height="60">
       <StackPanel Orientation="Horizontal" >
           <RichTextBlock Foreground="Black" FontSize="20" TextAlignment="Left" FontFamily="Segoe UI">
         <Paragraph>
        <TextBlock x:Name="txtBlkDatePrint" Margin="10,10,0,0" HorizontalAlignment="Left" TextWrapping="Wrap" FontSize="28" Text="" VerticalAlignment="Top" Height="39" Width="204"/>
        </Paragraph>
          </RichTextBlock>
       </StackPanel>
</StackPanel>


1

1 Answers

0
votes

So, Paragraph takes in a collection of Blocks as Content, of which TextBlock ironically is not. Try instead using a Run.

<StackPanel x:Name="header" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,0,0" Grid.Row="0" Height="60">
    <StackPanel Orientation="Horizontal" >
        <RichTextBlock Foreground="Black" FontSize="20" TextAlignment="Left" FontFamily="Segoe UI">
            <Paragraph>
                <Run x:Name="txtBlkDatePrint" TextWrapping="Wrap" FontSize="28" Text=""/>
            </Paragraph>
         </RichTextBlock>
     </StackPanel>
</StackPanel>

Though, if you just want to display simple text, you may not need the RichTextBlock at all.