XPS ドキュメントを作成するために Web サービスを使用する Silverlight アプリケーションがあります。ドキュメント テンプレートは、WCF クラス ライブラリの XAML コントロールとして作成されます。
public void GenerateXPS()
{
Type typeofControl = Type.GetType(DOCUMENT_GENERATOR_NAMESPACE + "." + ControlTypeName, true);
FrameworkElement control = (FrameworkElement)(Activator.CreateInstance(typeofControl));
control.DataContext = DataContext;
FixedDocument fixedDoc = new FixedDocument();
PageContent pageContent = new PageContent();
FixedPage fixedPage = new FixedPage();
//Create first page of document
fixedPage.Children.Add(control);
((IAddChild)pageContent).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
XpsDocument xpsd = new XpsDocument(OutputFilePath + "\\" + OutputFileName, FileAccess.ReadWrite);
System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
xw.Write(fixedDoc);
xpsd.Close();
SaveToDocumentRepository();
}
実際のデータをドキュメント テンプレートにバインドするために、コントロールの DataContext プロパティを設定します。問題は、XPS を見ると、画像 (画像コントロールのソースを画像の URL を表す文字列プロパティにバインド) が読み込まれていないかのように表示されないことです。どうすればこの問題を解決できますか? ありがとう!