我目前面临将 Plotmodel 打印到 XPS 文件的问题。
到目前为止我所拥有的:
/// <summary>
/// Plotmodel to XPS-File
/// </summary>
/// <param name="model">The model</param>
/// <param name="fileName">The fileName</param>
/// <param name="width">Width of the model</param>
/// <param name="height">Height of the model</param>
public void Export(PlotModel model, string fileName, double width, double height)
{
try
{
using (Package xpsPackage = Package.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
using (var doc = new XpsDocument(xpsPackage))
{
var g = new Grid();
var p = new OxyPlot.Wpf.Plot { Model = model }; //Problem?
g.Children.Add(p);
var size = new Size(width, height);
g.Measure(size);
g.Arrange(new Rect(size));
g.UpdateLayout();
if (xpsdw == null) //XpsDocumentWriter xpsdw
xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);
}
if (xpsdw != null)
{
xpsdw.Write(g);
}
}
}
}
此代码工作正常(一次),但问题是:无论您多久使用此方法,您将始终只有一个包含数据的页面。因此,如果您想将第二个 Plotmodel 打印到 XPS 文件中,旧的将被删除,您只能看到新的。
所以问题是: 你有一个想法,如何将新的 Plotmodel 附加到旧的 XPS 文件而不覆盖它?
我也尝试使用:
XpsExporter.Export(model, fileName, width, height);
而不是我的功能,但这也不起作用。