2

I am building up data in a flow document. The user can alter some properties and see a Live "Print Preview". I do this by simply converting the FlowDocument to a Fixed Document (using the following method from this post) and display in a DocumentViewer.

public static FixedDocument ToFixedDocument(this FlowDocument flowDocument)
{
    var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
    var package = Package.Open(new MemoryStream(), FileMode.Create, FileAccess.ReadWrite);
    var packUri = new Uri("pack://temp.xps");
    PackageStore.RemovePackage(packUri);
    PackageStore.AddPackage(packUri, package);
    var xps = new XpsDocument(package, CompressionOption.NotCompressed, packUri.ToString());
    XpsDocument.CreateXpsDocumentWriter(xps).Write(paginator);
    FixedDocument doc = xps.GetFixedDocumentSequence().References[0].GetDocument(true);
    return doc;
}

However any datagrids that have been added to the FlowDocument are not being rendered correctly in the FixedDocument. They appear in the FixedDocument with no data; the shape of the grid is correct, with column headers and rows, just no data.

Originally I thought it might have been because the datagrids are contained within a BlockUIContainer in the FlowDocument, however I have other BlockUIContainer elements containing a Grid (with TextBlocks) and even an Xceed DataGridControl. They all render just fine in the FixedDocument.

I see there are other questions elsewhere about displaying DataGrids, but they convert the DataGrid to Tables, or create a DocumentPaginator to repaginate a datagrid when it spans multiple pages. Neither of these work for me, I want to see the DataGrid in the FixedDocument exactly as it appears in the FlowDocument

Why is the DataGrid not displaying correctly in the FixedDocument?

Community
  • 1
  • 1
Jason
  • 617
  • 9
  • 22
  • sounds like a great time to start using the debugger.. have you stepped through the code at all.. – MethodMan Mar 05 '15 at 14:28
  • Yes of course I've been through it, I don't just post without putting effort in first. However, I have not yet been able to detect the cause, hence why I've eventually posted here. – Jason Mar 05 '15 at 15:15

0 Answers0