创建XPS时,带有InlineUIContainer(image,datagrid)的FlowDocument会出现问题

时间:2013-10-30 11:12:00

标签: wpf datagrid flowdocument xps inlineuicontainer

我正在尝试将FlowDocument保存为XPS。我正在使用.Net 4.0。 FlowDocument包含以下元素:

    <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>

当我在WPF应用程序中显示FlowDocument时,一切正常。

现在,我需要将其转换为服务器上的XPS文件(我想批量打印!)。

所以我使用以下代码:

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();
        }

猜猜是什么? 1)图像丢失 2)虽然绘制了线条,但DataGrid是空的 =&GT;仅正确显示“运行”

我尝试了在网络上找到的各种组合,但它从未出现过属性。 任何非自动化的解决方案都是不可能的!

我等不及有人救我了!!! 提前致谢

1 个答案:

答案 0 :(得分:0)