如何打印日期

时间:2013-11-18 08:02:07

标签: winrt-xaml

我有两个用于打印的页面。

1)PagePrinting.xaml
2)FormattedPage.xaml

在PagePrinting.xaml中,我使用下面的代码来引用FormattedPage.xaml

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

问题:

  • 当PagePrinting.xaml中显示时,txtBlkDatePrint为空白

我需要做什么?


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 个答案:

答案 0 :(得分:0)

因此,ParagraphBlock的{​​{1}}收集为Content,其中TextBlock具有讽刺意味。请尝试使用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>

但是,如果您只想显示简单文字,则可能根本不需要RichTextBlock