如何设置 WPF FlowDocument 的原始宽度

发布于 2024-10-31 08:39:58 字数 3905 浏览 4 评论 0原文

我有这样的 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>

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夕嗳→ 2024-11-07 08:39:59

设置 FlowDocument ColumnWidth="999999"

Set the FlowDocument ColumnWidth="999999"

吝吻 2024-11-07 08:39:59

FlowDocument 对象支持您在 PageWidth、PagePadding 属性中寻找的功能。 ColumnWidth 属性不会影响页面宽度,而是建议或强制执行列在页面宽度范围内的布局方式。

有关该主题的博客的更多详细信息:

PageWidth:正如它所指示的,这是文档页面的宽度。该数量以与设备无关的像素为单位设置(像素是英寸的 1/96,因此 1” = 96 像素)。请记住,设置此值时,还必须考虑页边距。

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

ColumnWidth:这与容器的大小无关,而与容器内内容的布局方式有关。顾名思义,它设置文档列的所需宽度。这只是需要的,因为默认情况下,布局将调整ColumnWidth以充分利用页面的可用宽度。要强制执行列宽设置,您需要设置 IsColumnWidthFlexible = False。

完整博客文章此处

MSDN 上的 PagePadding 属性

MSDN 关于 PageWidth 属性

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

李不 2024-11-07 08:39:59

有关 FlowDocument.ColumnWidth 属性的一些社区内容,http://msdn.microsoft.com/en-us/library/system.windows.documents.flowdocument.columnwidth(v=vs.85).aspx 表示“默认情况下,流文档的列宽是字体大小的 20 倍”。我将 FontSize="40" 添加到 FlowDocument 并获得了可以使用的宽度。我只需要在其他地方也提供 FontSizes,因为我真的不想要 40。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文