I have a Silverlight application which uses a web service in order to create XPS documents. The document templates are created as XAML controls in a WCF class library.
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();
}
In order to bind the actual data to my document template I set the DataContext property of the control. The problem is that when I look at my XPS, the images (I bind the Source of my Image controls to a string property that represents the URL of my image) are not displayed as if they were not loaded. How can I solve this problem? Thanks!