2011-02-01 6 views
4

인쇄 할 임의의 수의 열과 행을 포함하는 DataTable이 있습니다. 지금까지 해본 최고의 행운은 테이블에 데이터를 넣은 다음 테이블을 FlowDocument에 추가하는 것입니다.WPF - FlowDocument - 전체 폭으로 늘이기 테이블?

지금까지 그렇게 좋았습니다. 지금 당장 가지고있는 문제는 테이블이 문서의 너비의 약 절반을 차지하고 싶어한다는 것입니다. FlowDocument의 PageWidth 및 ColumnWidth 속성에 대한 적절한 값을 이미 설정했지만 테이블이 할당 된 공간을 채우기 위해 늘어나지 않는 것처럼 보입니까?

+0

FixedDocument를 사용하여이 기능을 사용할 수있게되었지만 누구나 FlowDocument 사용에 대한 통찰력이 있다면 여전히 듣고 싶습니다. –

답변

0

나는 공간의 약 90 % 만 차지했지만, 이걸 가지고는 행운이있다 : How to set the original width of a WPF FlowDocument.

+0

사실 10 % 사용되지 않은 공간은 FlowDocument에 PagePadding = "0.5in"을 추가했기 때문입니다. 이는 인쇄 할 때 페이지가 잘리지 않게하는 데 필요했습니다. –

4

FlowDocument의 내용을 전체 widh로 설정하려면 먼저 페이지 너비를 알아야합니다. 내용 길이를 처리해야하는 속성은 FlowDocument의 자로 ColumnWidth입니다.

보통 "PrintLayout"도우미 클래스를 만들어 페이지 너비/높이 및 패딩에 대한 알려진 미리 설정을 유지합니다. Wou는 Ms Word에서 미리 설정을 스니핑하고 더 채울 수 있습니다.

당신이 코드에 의해 사전 설정 XAML

<FlowDocument x:Class="WpfApp.MyPrintoutView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:local="clr-namespace:WpfApp" 
     mc:Ignorable="d" 
     PageHeight="{Binding Height, Source={x:Static local:PrintLayout.A4}}" 
     PageWidth="{Binding Width, Source={x:Static local:PrintLayout.A4}}" 
     PagePadding="{Binding Margin, Source={x:Static local:PrintLayout.A4}}" 
     ColumnWidth="{Binding ColumnWidth, Source={x:Static local:PrintLayout.A4}}" 
     FontFamily="Segoe WP" 
     FontSize="16" ColumnGap="4"> 
     <!-- flow elements --> 
</FlowDocument> 

을 설정할 수 있습니다 FlowDocument에

public class PrintLayout 
{ 
    public static readonly PrintLayout A4 = new PrintLayout("29.7cm", "42cm", "3.18cm", "2.54cm"); 
    public static readonly PrintLayout A4Narrow = new PrintLayout("29.7cm", "42cm", "1.27cm", "1.27cm"); 
    public static readonly PrintLayout A4Moderate = new PrintLayout("29.7cm", "42cm", "1.91cm", "2.54cm"); 

    private Size _Size; 
    private Thickness _Margin; 

    public PrintLayout(string w, string h, string leftright, string topbottom) 
     : this(w,h,leftright, topbottom, leftright, topbottom) { 
    } 

    public PrintLayout(string w, string h, string left, string top, string right, string bottom) { 
     var converter = new LengthConverter(); 
     var width = (double)converter.ConvertFromInvariantString(w); 
     var height = (double)converter.ConvertFromInvariantString(h); 
     var marginLeft = (double)converter.ConvertFromInvariantString(left); 
     var marginTop = (double)converter.ConvertFromInvariantString(top); 
     var marginRight = (double)converter.ConvertFromInvariantString(right); 
     var marginBottom = (double)converter.ConvertFromInvariantString(bottom); 
     this._Size = new Size(width, height); 
     this._Margin = new Thickness(marginLeft, marginTop, marginRight, marginBottom); 

    } 


    public Thickness Margin { 
     get { return _Margin; } 
     set { _Margin = value; } 
    } 

    public Size Size { 
     get { return _Size; } 
    } 

    public double ColumnWidth { 
     get { 
      var column = 0.0; 
      column = this.Size.Width - Margin.Left - Margin.Right; 
      return column; 
     } 
    } 
} 

다음 PrintLayout의 클래스

FlowDocument result = new WpfApp.MyPrintoutView(); 
result.PageWidth = PrintLayout.A4.Size.Width; 
result.PageHeight = PrintLayout.A4.Size.Height; 
result.PagePadding = PrintLayout.A4.Margin; 
result.ColumnWidth = PrintLayout.A4.ColumnWidth; 
+1

감사합니다. 덕분에 많은 도움이되었습니다. 사소한 수정 : A4 용지 크기는 21cm x 29.7cm, A3는 29.7cm x 42cm입니다. – solarc