What des it mean by the following sentence
DependencyObjects are 开发者_开发知识库not marked as serializable
To my knowledge, I can have a class which inherits from DependencyObject...and I can mark it as serializable. Anyway serialize property is not inheritable.
Could someone make me clear. Thanks in advance.
This means that a class that derives from DependencyObject cannot be serialized with standard serializers. As a workaround you could use XamlReader/XamlWriter as shown in this article.
DependencyObject exists to make use of the entire dependency property system. One side effect of this is that it really doesn't mesh with the approach to serialization taken in .NET.
Serialization, in .NET, serializes fields in a class. However, DependencyObjects don't actually use (instance) fields, but rather registered DependencyProperties, which are stored elsewhere (if at all). As such, they don't serialize properly, even if you mark them [Serializable].
精彩评论