You could achieve this through the FlowDocument:
<FlowDocumentReader>
<FlowDocument
Name="flowDocument"
ColumnWidth="400" FontSize="14" FontFamily="Georgia">
<Paragraph>
<Grid>
<Rectangle Fill="Red" Width="200" Height="100"/>
<TextBlock Text="Hello World!" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
The code behind would then look like:
public static void SaveAsXps(string path, FlowDocument document)
{
using (var package = Package.Open(path, FileMode.Create))
{
using (var xpsDocument = new XpsDocument(package, System.IO.Packaging.CompressionOption.Maximum))
{
var xpsSerializationManager = new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false);
var documentPaginator = ((IDocumentPaginatorSource)document).DocumentPaginator;
xpsSerializationManager.SaveAsXaml(documentPaginator);
}
}
}
And the calling code:
SaveAsXps("temp.xps", flowDocument);
Just another way to do it. I personally prefer keeping the UI in XAML.
You'll need to add a reference to ReachFramework.dll for this to work.