3

FlowDocument を印刷しようとしています。複数のページを試して一日の大半を費やした後、私は失敗し、より単純なものを選択しましたが、テキストがページに出力されない場合を説明するのに途方に暮れています. これは、私が雪盲になったものに違いないと思います。以下に 2 つの表を示します。両方にコンバーターを配置すると、FlowDocument の DataContext を介して値が設定されていることがわかります。

<Table>
    <Table.Columns>
        <TableColumn Width="Auto"/>
        <TableColumn Width="34"/>
        <TableColumn Width="Auto"/>
    </Table.Columns>
    <TableRowGroup>
        <TableRow>
            <TableCell>
                <Paragraph>
                    <Image Source="{Binding Icon,Converter={StaticResource IconConverter},ConverterParameter=32}" Width="32" Height="32"/>
                </Paragraph>
            </TableCell>
            <TableCell>
                <Paragraph>
                    <TextBlock Text="{Binding Name,Converter={StaticResource dbg}}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" FontSize="18" Foreground="Black" />
                </Paragraph>
            </TableCell>
            <TableCell>
                <Paragraph>
                    <TextBlock Text="Static text works fine" TextAlignment="Right"  />
                    <TextBlock Text="Static text works here too fine" TextAlignment="Right"  />
                </Paragraph>
            </TableCell>
        </TableRow>
    </TableRowGroup>
</Table>
<BlockUIContainer>
    <Line Stretch="Fill" Stroke="DarkBlue" X2="1"/>
</BlockUIContainer>

ドキュメントは次を使用して印刷されます。

PrintDialog dlg = new PrintDialog();
if(dlg.ShowDialog() == true) {
  int margin = 5;
  Size pageSize = new Size(dlg.PrintableAreaWidth - margin * 2, dlg.PrintableAreaHeight - margin * 2);
  FlowDocument document = WPFUtils.LoadFlowDocument(System.IO.Path.Combine(Utils.GetApplicationPath(), "AccountPrintView.xaml"), account); // loads the document from a XAML file
  IDocumentPaginatorSource paginator = document as IDocumentPaginatorSource;
  paginator.DocumentPaginator.PageSize = pageSize;
  dlg.PrintDocument(paginator.DocumentPaginator, "Print output");
}

私はこれで頭がおかしくなり、問題がわかりません。誰かが光を当てることができれば、本当に感謝しています。

4

1 に答える 1

1

これは実際には答えではありませんが、FlowDocumentReader を使用する立場にありますか? Ctrl-P で既に事前に配線された印刷機能があります (そして、「印刷」メソッドを公開します)

于 2009-12-30T20:49:18.207 に答える