【问题标题】:Printing flowdocument adds border to table打印流程文档为表格添加边框
【发布时间】:2021-12-31 22:17:18
【问题描述】:

我正在从 ViewModel 构建流文档,然后将其打印为 pdf。

<UserControl x:Class="WpfApplication5.View.TransferTemplate" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:p="clr-namespace:WpfApplication5.Properties" xmlns:viewmodels="clr-namespace:WpfApplication5.ViewModels" d:DataContext="{d:DesignInstance Type=viewmodels:WarehouseActionViewModel}" mc:Ignorable="d"
  x:Name="templ">
  <FlowDocument FontFamily="Cambria" FontSize="14" Background="White" x:Name="doc" d:ColumnWidth="1024">

    <Paragraph>
      <Run>Date: </Run>
      <Run Text="{Binding Action.ActionDate, StringFormat=dd-MM-yyyy}" />
    </Paragraph>
    <Paragraph>
      <Run>Note: </Run>
      <Run Text="{Binding Action.Note}" />
    </Paragraph>
    <Paragraph>
      <Run>Sender: </Run>
      <Run Text="{Binding Action.WarehouseFrom}" />
    </Paragraph>
    <Paragraph>
      <Run>Receiver: </Run>
      <Run Text="{Binding Action.WarehouseTo}" />
    </Paragraph>

    <Table x:Name="border" CellSpacing="0" BorderThickness="0" Background="{StaticResource WhiteBg}" BorderBrush="{StaticResource WhiteBg}">
      <Table.Columns>
        <TableColumn Width="0.2*" />
        <TableColumn Width="0.7*" />
        <TableColumn Width="0.1*" />
      </Table.Columns>

      <TableRowGroup>
        <TableRow FontSize="16">
          <TableCell BorderThickness="0,1,0,1" BorderBrush="#CCCCCC" Padding="5">
            <Paragraph>
              <Run Text="{x:Static p:Resources.barcode}" d:Text="Code" />
            </Paragraph>
          </TableCell>
          <TableCell BorderThickness="0,1,0,1" BorderBrush="#CCCCCC" Padding="5">
            <Paragraph>
              <Run Text="{x:Static p:Resources.Name}" d:Text="Name" />
            </Paragraph>
          </TableCell>
          <TableCell BorderThickness="0,1,0,1" BorderBrush="#CCCCCC" Padding="5">
            <Paragraph>
              <Run Text="{x:Static p:Resources.quantity}" d:Text="Quantity" />
            </Paragraph>
          </TableCell>
        </TableRow>
        <TableRow/>
      </TableRowGroup>
    </Table>
  </FlowDocument>
</UserControl>



PrintDialog printDlg = new PrintDialog();
        FlowDocument f = new TransferTemplate(vm).doc;
        f.ColumnWidth = printDlg.PrintableAreaWidth;
        IDocumentPaginatorSource dps = f;
        if ((bool)printDlg.ShowDialog())
        {
            printDlg.PrintDocument(dps.DocumentPaginator, "flow doc");
        }

问题是当我从模板创建它并打印它时,它会在表格中添加黑色边框 (边框粗细设置为0) [![在此处输入图片描述][1]][1]

但是当我在 c# 中使用相同代码创建没有 xaml 模板的文档时,它不会添加边框 (未设置边框粗细)

var table1 = new Table
        {
            CellSpacing = 0,
            Background = Brushes.White
        };
        flowDoc.Blocks.Add(table1);
enter code here

[![在此处输入图片描述][2]][2]

如何修复 XAML 模板以禁用边框? [1]:https://i.stack.imgur.com/BlYhX.png [2]:https://i.stack.imgur.com/HoZnF.png

【问题讨论】:

  • 尝试将 BorderBrush 设置为 null ,也许它会工作!!!
  • @Romylussone,谢谢,但没用

标签: wpf xaml pdf printing flowdocument


【解决方案1】:

刚刚从表中删除了x:Name,它起作用了!

提示:将Name 属性添加到任何Flowdocument 块元素会在打印时添加黑色边框(我只测试了打印到PDF)。

【讨论】:

    猜你喜欢
    • 2010-12-12
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    • 1970-01-01
    相关资源
    最近更新 更多