如何设置WPF FlowDocument的原始宽度

Kel*_*ine 3 wpf xaml flowdocument

我有这个XAML结构:

<wft:Dialog x:Class="WFT.PumpSvc.Bench.Parts.PartsPullListDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wft="http://schemas.Weatherford.com">
    <wft:Dialog.Resources>
        <ResourceDictionary Source="../Resources.xaml" />
    </wft:Dialog.Resources>
    <wft:CaptionedBox Style="{StaticResource HeaderCaptionedBox}" Name="captionedBox"  Caption="Parts Pull List">
        <DockPanel>
            <DockPanel DockPanel.Dock="Right">
                <StackPanel Orientation="Vertical" DockPanel.Dock="Top">
                    <wft:TouchButton Name="closeButton">Cancel</wft:TouchButton>
                </StackPanel>
                <StackPanel Orientation="Vertical" VerticalAlignment="Bottom">
                    <wft:TouchButton Name="printButton">Print</wft:TouchButton>
                </StackPanel>
            </DockPanel>

            <wft:CaptionedBox Caption="Preview">
                <FlowDocumentPageViewer Name="documentReader">
                    <FlowDocument Background="White">
                        <Paragraph FontSize="20" FontWeight="Bold">Parts Pull List</Paragraph>
                        <Table FontWeight="Bold">
                            <Table.Columns>
                                <TableColumn Width="*" />
                                <TableColumn Width="2*" />
                            </Table.Columns>
                            <TableRowGroup>
                                <TableRow>
                                    <TableCell>...
                                    <TableCell>...
                                </TableRow>
                                <TableRow>...
                                <TableRow>...
                            </TableRowGroup>
                        </Table>
                        <Table>
                            <Table.Columns>
                                <TableColumn Width="1*" />
                                <TableColumn Width="1*" />
                                <TableColumn Width="1*" />
                                <TableColumn Width="1*" />
                                <TableColumn Width="1*" />
                                <TableColumn Width="1*" />
                                <TableColumn Width="1*" />
                            </Table.Columns>
                            <TableRowGroup Name="partRowGroup">
                                <TableRow>
                                    <TableCell>
                                        <Paragraph>
                                            <Underline>SubAssembly Type</Underline>
                                        </Paragraph>
                                    </TableCell>
                                    <TableCell>...
                                    <TableCell>...
                                    <TableCell>...
                                    <TableCell>...
                                    <TableCell>...
                                    <TableCell>...
                                </TableRow>
                            </TableRowGroup>
                        </Table>
                    </FlowDocument>
                </FlowDocumentPageViewer>
            </wft:CaptionedBox>
        </DockPanel>
    </wft:CaptionedBox>
</wft:Dialog>
Run Code Online (Sandbox Code Playgroud)

如您所见,我的页面上没有任何宽度设置.但是,我的表只占FlowDocument中水平空间的一半.什么控制了这个?

Kel*_*ine 18

设置FlowDocument ColumnWidth ="999999"

  • 我不敢相信我花了无数个小时来研究如何增加 FlowDocument 的宽度,这就是解决方案! (2认同)

The*_*ker 7

FlowDocument对象支持您在PageWidth,PagePadding属性中查找的功能.ColumnWidth属性不会影响页面宽度,而是建议或可以强制执行如何在页面宽度的范围内布置列.

关于这个主题的博客的更多细节:

PageWidth:这表示文档页面的宽度.该量设置在与设备无关的像素中(像素是1/96英寸,因此1"= 96像素).请记住,在设置此值时,还必须考虑页边距.

PagePadding:这个名称,更适合WPF然后在文档中,实际上是页边距.纸张边缘与内容之间的像素数量(1/96英寸).所以基本上,PagePadding + PageWidth应该等于或至少不大于纸张宽度.如果你有8.5英寸宽的纸张(816像素)并且你有1/2边距(48像素*2 = 96)那么你只有720像素可以用于PageWidth.PagePadding属于"类型厚度",因此您可以设置适用于所有边距的统一值,或者根据需要单独设置每个边距.

ColumnWidth:这个与容器的大小无关,就像容器中的内容的布局方式一样.如名称所示,它设置文档列的所需宽度.它只是需要,因为默认情况下,布局将调整ColumnWidth以充分利用页面的可用宽度.要强制执行列宽设置,需要设置IsColumnWidthFlexible = False.

完整博客文章在这里

PagePadding属性上的MSDN

页面宽度属性上的MSDN