How to set the original width of a WPF FlowDocumen

2019-01-26 20:19发布

I have this XAML structure:

<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>

As you see, I don't have any width settings on my page. However, my Tables only occupy half the horizontal space in the FlowDocument. What controls this?

3条回答
Evening l夕情丶
2楼-- · 2019-01-26 20:54

The FlowDocument object supports the functionality you are looking for in the PageWidth, PagePadding properties. The ColumnWidth property does not affect the page width, rather it suggests, or can enforce, how columns are laid out within the confines of the page width.

Some more details from a blog on the subject:

PageWidth: this, as it indicates, is the width of the document page. The amount is set in device independent pixels (a pixel is 1/96 of an inch so 1” = 96 pixels). Keep in mind, when setting this value, that the page margin must also be considered.

PagePadding: this name, that is much more fitting in WPF then in document land, is actually the page margin. The amount of pixels (1/96 of an inch) between the edge of the paper and the content. So basically, PagePadding + PageWidth should equal, or at least not be greater than, the paper width. If you have 8.5” wide paper (816 pixels) and you have 1/2 margins (48 pixels * 2 = 96) then you only have 720 pixels to play with for PageWidth. PagePadding is of Type Thickness, so you can set a uniform value that applies to all Margins, or set each separately if desired.

ColumnWidth: This one is not related to the size of the container as much as it is how the content within the container is laid out. As the name indicates, it sets the desired width of the columns of the document. It is only desired since, by default, the layout will adjust the ColumnWidth to make best use of the available width of the page. To enforce your column width setting you need to set IsColumnWidthFlexible = False.

full blog post here

MSDN on PagePadding Property

MSDN on PageWidth Property

查看更多
Viruses.
3楼-- · 2019-01-26 20:55

Some Community Content on FlowDocument.ColumnWidth property, http://msdn.microsoft.com/en-us/library/system.windows.documents.flowdocument.columnwidth(v=vs.85).aspx, says "By default, a Flow Document’s column width is 20 times the font size". I added FontSize="40" to the FlowDocument and got a width I could work with. I just had to provide FontSizes everywhere else, too, because I really didn't want 40.

查看更多
迷人小祖宗
4楼-- · 2019-01-26 21:04

Set the FlowDocument ColumnWidth="999999"

查看更多
登录 后发表回答