我正在從 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
uj5u.com熱心網友回復:
剛剛從桌子上x:Name取下來,它起作用了!
提示:將Name屬性添加到任何 Flowdocument 塊元素會在列印時添加黑色邊框(我只測驗了列印到 PDF)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/371411.html
上一篇:XAMLWPFDataGrid:在滾動時減少列寬以適應其內容,除了一個
下一篇:多個表通過單列連接到一個表
