0

I'm trying to save a FlowDocument as a XPS. I'm using .Net 4.0. The FlowDocument contains the following elements:

    <Paragraph>
    <InlineUIContainer BaselineAlignment="Center">
        <Image Source="/MyNamespace;component/Images/logo.png"/>
    </InlineUIContainer>
</Paragraph>

    <Paragraph>
    <Run Text="{Binding Path=TextBinding, FallbackValue='Oups, binding did not work'}"></Run>
</Paragraph>

<InlineUIContainer>
        <DataGrid ItemsSource="{Binding Path=Items}" AutoGenerateColumns="False"
                  CanUserAddRows="False" RowHeaderWidth="0">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Item Number"
                                    Binding="{Binding Path=Id}" Width="100" />
                <DataGridTextColumn Header="Description"
                                    Binding="{Binding Path=ItemDescription}" Width="200" />
            </DataGrid.Columns>
        </DataGrid>
    </InlineUIContainer>

Everything works just fine when I display that FlowDocument within my WPF app.

Now, I need to convert this into a XPS file on a server (I'd like to print in batch!).

So I'm using the following code:

flowDocument.DataContext = myViewModel;

            Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.SystemIdle,
                                                new DispatcherOperationCallback(arg => null), null);

 string xpsFilePath = String.Concat(@"c:\temp\", Guid.NewGuid(), ".xps");

        using (FileStream outputFile = new FileStream(xpsFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
        using (Package package = Package.Open(outputFile, FileMode.Create, FileAccess.ReadWrite))
        using (XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Maximum))
        {
            XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false);
            DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
            rsm.SaveAsXaml(paginator);
            rsm.Commit();
        }

And guess what? 1) The image is missing 2) The DataGrid's empty, although the lines are drawn => Only the Run is displayed properly

I tried all sorts of combinations found on the web, but it just never comes out propertly. And any non automated solution is just so out of the question!!!

I can't wait for someone to rescue me!!! Thanks in advance

4

1 回答 1

0

http://social.msdn.microsoft.com/Forums/en-US/51b358e5-8d59-43a5-b5e6-d9bd90f59692/problem-with-saving-inlineuicontainer-items-in-a-flowdocument接近尾声

这是 Silverlight 的答案,但我猜也应该与 WPF 一起使用

于 2014-02-25T09:05:19.423 回答