开发者

Access Derived class properties from base class collection

I have created a derived class from a base class and have added the derived class objec开发者_StackOverflow中文版ts to the base class collection.Later when i try to cast the collection objects to derived class,it is throwing error and i am not able to get my override methods and properties.How could i get around this.?

I am trying to override the stroke class in wpf inkcanvas.But the collection available is of base ink collection.So after serializing ans desalinizing,the new properties that i added is not accessible.Pls help


Your problem is that StrokeCollection implements a custom TypeConverter which serializes the stroke data in an efficient binary format called Ink Serialization Format (ISF) using the StrokeCollection.Save() method. When your strokes are converted to ISF all the extra data is lost, so when they are reloaded they are instantiated as ordinary Stroke objects (not your subclass). This is why you cannot cast them to your subclass.

Some of your options are:

  • Subclass StrokeCollection and implement a new TypeConverter for your subclass
  • Use a different serialization technique that ignores the TypeConverter
  • Manually serialize your StrokeCollection (eg. by copying the Strokes into a List<Stroke> and serializing that)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜