How to set the original width of WPF 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 can see, I have no width settings on my page. However, my tables occupy half the horizontal space in the FlowDocument. What controls this?

+2
source share
3 answers

Set FlowDocument ColumnWidth = "999999"

+15
source

The FlowDocument object supports the functions you are looking for in the PageWidth, PagePadding properties. The ColumnWidth property does not affect the page width; rather, it assumes, or can provide, how columns are laid out within the page width.

Some details from the related blog:

PageWidth : this, as he points out, is the width of the document page. The number is set to device-independent pixels (the pixel is 1/96 inch, so 1 "= 96 pixels). Remember that when setting this value, you should also take into account that the page margin should also be taken into account.

PagePadding : this is the name that is much more relevant in WPF and then in the document, is actually the border of the page. The number of pixels (1/96 inch) between the edge of the paper and the content. Thus, PagePadding + PageWidth should be equal to, or at least no greater than, the width of the paper. If you have 8.5 inches (816 pixels) wide paper and you have 1/2 margins (48 pixels * 2 = 96), then you can only use 720 pixels for PageWidth. PagePadding has a type thickness, so you can set a uniform value that applies to all margins, or set each separately if necessary.

ColumnWidth . This is not related to the size of the container, as it is placed in the contents of the container. As the name is specified, it sets the desired width of the document columns. This is desirable since the default layout will adjust ColumnWidth to make the best use of the available page width. To enable column width adjustment, you need to set IsColumnWidthFlexible = False.

full blog entry here

MSDN on the PagePadding property

MSDN in the PageWidth property

+5
source

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

0
source

Source: https://habr.com/ru/post/1337882/


All Articles