如何设置WPF FlowDocument的原始宽度

5

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>

您看到了,我的页面上没有任何宽度设置。然而,我的表格在FlowDocument中只占据了一半的水平空间。这是由什么控制的?


在这里使用预设来检查一个解决方案 链接 - cleftheris
3个回答

25

将FlowDocument的ColumnWidth设置为"999999"


1
我简直不敢相信我花了无数个小时来解决如何增加FlowDocument的宽度,而这就是解决方案! - Darth Coder

7
FlowDocument对象支持您在PageWidth,PagePadding属性中寻找的功能。ColumnWidth属性不会影响页面宽度,而是建议或可以强制执行列在页面宽度范围内的布局方式。
下面是关于此主题的博客上的更多细节:

PageWidth: 这是文档页面的宽度。该值以设备无关像素为单位设置(一个像素等于1/96英寸,因此1英寸= 96像素)。请记住,在设置此值时,必须考虑页面边距。

PagePadding: 在WPF中更适合使用的名称,实际上是页面边距。即纸张边缘和内容之间的像素(1/96英寸)。因此,PagePadding + PageWidth应等于或至少不大于纸张宽度。如果您有8.5英寸宽的纸张(816像素)并且有1/2边距(48像素*2 = 96),则在PageWidth中只有720像素可供使用。 PagePadding的类型为Thickness,因此可以设置适用于所有边距的统一值,或者根据需要分别设置每个边距。

ColumnWidth: 这与容器的大小关系不大,而是与容器内的内容布局方式有关。如名称所示,它设置文档列的所需宽度。由于默认情况下,布局将调整ColumnWidth以最佳利用页面的可用宽度,因此它仅是所需宽度。要强制执行列宽度设置,您需要设置IsColumnWidthFlexible = False。

点击此处查看完整博客文章

PagePadding 属性的 MSDN 文档

PageWidth 属性的 MSDN 文档


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接