UWPアプリケーションからテキストのページを印刷しようとしていますが、整列に問題があります。 TextBlockをグリッド内の中心に位置するように整列される方法テキストボックスの整列UWPから印刷する場合
<Grid Background="White">
<TextBlock Text="Welcome Printed World!" FontSize="36" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
お知らせ:まず第一に、私は次のXAMLを含むページを作成しました。
次に、さまざまなPrintDocumentイベントハンドラを使用して印刷します。この(マージンと非印刷可能領域を無視するために簡略化)、プレビューにそれを印刷するためのコード:
Page printPage;
private void OnPrintDocumentPaginate(object sender, PaginateEventArgs e)
{
// Construct an instance of the page to print, and tell Windows that there is only 1 page
this.printPage = new PrintPage();
printDocument.SetPreviewPageCount(1, PreviewPageCountType.Final);
}
private void OnPrintDocumentGetPreviewPage(object sender, GetPreviewPageEventArgs e)
{
// Give Windows a reference to the page to print for preview
this.printDocument.SetPreviewPage(e.PageNumber, this.printPage);
}
、これは、それが印刷する方法である:テキストブロックを中心にされていないことを
お知らせ。私はこのように、国境でのTextBlockをラップする場合
しかし、:
<Grid Background="White">
<Border HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="Welcome Printed World!" FontSize="36" Foreground="Black"/>
</Border>
</Grid>
そして、それは結構です。
使用した場合のTextBlockを中心にされていない理由を誰が見ることができます元のxaml?
グリッドの中心に垂直方向の位置合わせと水平方向の位置合わせも行います。 – Archana
これでうまくいきましたが、他の場所、たとえば右下に他のTextBlockを配置したい場合は問題があります。そのため、グリッドがページを埋める必要があると思います。私が見つけたのは、BorderThickessが0のTextBlockの代わりにTextBoxを使うことができるので、印刷されたページのテキストだけです。 –