How can I use a WPF FlowDocument or FixedDocument to compose a printable page from on screen controls?

StackOverflow https://stackoverflow.com/questions/3853803

문제

I'm attempting to print a number of WPF controls (datagrid, charts etc) that are on screen in my application but which need to be re-arranged and supplemented with other text etc.

Using the WPF FlowDocument or FixedDocument seems the obvious way to compose and print documents but I'm struggling to achieve this.

I've tried creating a VisualBrush from the control(s) and using this as the Fill on a Rectangle without success (the Rectangle is not displayed at all).

Has anyone used FlowDocument/FixedDocument to do this and/or have any example code showing how it's achieved?

도움이 되었습니까?

해결책

Found that it works okay if the FlowDocument is rendered before printing (e.g. if hosted in a FlowDocumentReader).

XAML

    xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"

.

        <d3:ChartPlotter x:Name="plotter">
                <d3:Header TextBlock.FontSize="20">
                    Very simple chart
                </d3:Header>
            </d3:ChartPlotter>

.

            <FlowDocumentReader>
            <FlowDocument>
                <Paragraph>
                    <Run>Graph Header</Run>                        
                </Paragraph>
                <BlockUIContainer>
                    <Rectangle x:Name="GraphRectangle" Height="300"/>                            
                </BlockUIContainer>
            </FlowDocument>
        </FlowDocumentReader>

CS

    public MainWindow()
    {
        InitializeComponent();
        GraphRectangle.Fill = new VisualBrush(plotter);
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top