c# - 派生 FixedDocument 的序列化

标签 c# wpf serialization xps

由于只能给FixedDocument添加页面,所以我写了一个派生类:

public class CustomFixedDocument : FixedDocument
{
    public void RemoveChild(object child)
    {
        base.RemoveLogicalChild(child);
    }
}

替换 FixedDocument,它工作正常,直到我尝试打印文档并收到以下错误:

An unhandled exception of type 'System.Windows.Xps.XpsSerializationException' occurred in ReachFramework.dll

Additional information: Serialization of this type of object is not supported.

我过去没有那么多地使用序列化,并且已经阅读了它,但仍然无法解决问题。我也试过

[Serializable]

属性,但它没有任何区别。

谁能指导我正确的方向或有什么想法该怎么做?

最佳答案

如果查看检查是否支持某种类型的方法的反编译源代码,您将大致看到以下内容:

internal bool IsSerializedObjectTypeSupported(object serializedObject)
{
  bool flag = false;
  Type type = serializedObject.GetType();
  if (this._isBatchMode)
  {
    if (typeof (Visual).IsAssignableFrom(type) && type != typeof (FixedPage))
      flag = true;
  }
  else if (type == typeof (FixedDocumentSequence) || type == typeof (FixedDocument) || (type == typeof (FixedPage) || typeof (Visual).IsAssignableFrom(type)) || typeof (DocumentPaginator).IsAssignableFrom(type))
    flag = true;
  return flag;
}

这里你看到这个类型要么继承DocumentPaginator、Visual,要么完全是FixedDocument、FixedDocumentSequence、FixedPage类型。因此,无论您将使用什么可序列化属性,从 FixedDocument 继承的类型都不起作用,因此您必须找到不同的方法。我认为这是 XpsSerializationManager 中的错误,但也许有一些深层原因。

关于c# - 派生 FixedDocument 的序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32474210/

相关文章:

Java 对象转 JSON : Ignore Cycle

c# - 调用PayU rest api(创建订单)返回html而不是json响应

c# - 使用 mvvm 导航返回时,何时在 ListView 中重新加载项目

c# - 气球弹出 WPF

c# - 如何序列化具有接口(interface)作为属性的对象?

asp.net - 从 ApiController 中的 json 序列化中排除属性

c# - 判断两个表是否相关的函数

c# - 应用程序在 15 分钟后崩溃,WCE 6.0 CF 3.5 Motorola MC3190

c# - 如何在 WPF 4.0 中创建发光的文本框?

wpf - WPF (Silverlight) 布局 (Render)Transform 对应用性能的影响