I have created a derived class from a base class and have added the derived class objects 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
StrokeCollectionimplements a customTypeConverterwhich serializes the stroke data in an efficient binary format called Ink Serialization Format (ISF) using theStrokeCollection.Save()method. When your strokes are converted to ISF all the extra data is lost, so when they are reloaded they are instantiated as ordinaryStrokeobjects (not your subclass). This is why you cannot cast them to your subclass.Some of your options are:
StrokeCollectionand implement a newTypeConverterfor your subclassTypeConverterStrokeCollection(eg. by copying theStrokesinto aList<Stroke>and serializing that)