首页 文章

如何打印日期

提问于
浏览
0

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

1)PagePrinting.xaml
2)FormattedPage.xaml

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

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

问题:

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

我需要做什么?

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

    所以, ParagraphBlock 的集合作为 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 .

相关问题