We load FixedPage objects from an XPS document, process and displays it.The following code does the loading of the FixedPage from a Package:
FixedPage fp = null;
Package package; // xps package
Uri packageUri; // uri of the package in the package store
Uri fixedPageUri; // uri of the fixed page
Dispatcher _mainDispatcher // reference to the main dispatcher, passed to this function
// this function runs in a different thread
// get the fixed page stream
Stream stream = package.GetPart(fixedPageUri).GetStream();
// create a parser context to help XamlReader with the resources used in the page
ParserContext pc = new ParserContext();
pc.BaseUri = PackUriHelper.Create(packageUri, fixedPageUri);
_mainDispatcher.BeginInvoke(
new UIRenderDelegate(delegate()
{
// this line takes its sweet time
fp = XamlReader.Load(stream, pc) as FixedPage;
stream.Dispose();
}), null).Wait();
// return the created fixed page;
However, that XamlReader.Load() call takes a long time (especially for complex FixedPages) and sometimes blocks the UI. We could do this in another thread with it's own Dispatcher, but since the FixedPage class is not freeazable, its can't be used by the main UI thread.
Is there a way around this? Right now we're stuck rendering the FixedPages as images using RenderTargetBitmap since BitmapSource is Freezable.