Exception when serializing WPF outlines

I have an app (appointment manager) that allows the user to create custom controls on the stack for each button clicked and the user can enter data into usercontrols. So far so good.

I have serialized a stack panel using XamlWriter.Save (). But then when I try to load it again, next time the application starts with XamlReader.Load (), I get the following exception:

"System.Windows.Markup.XamlParseException: Unable to set the value of the Name attribute 'border1' on the element 'Border'." Border "is within the" Item "element that already had a name registered when it was defined in another area. Item" 4 "'43'".

I found a workaround on google that involves removing all the control names which I don't think are very useful.

Now you may be asking why you would need to use Xml-Serialization at all. The point is that we have to create a science project for our xml course that should use at least xml serialization and xslt, so I thought it would be a great idea :(

0


a source to share


1 answer


One piece of advice I would give you is not for serializing the UI, but rather for serializing the underlying data.

For example, create a Data class that represents the data stored in your custom control. Make sure this class is decorated with the [Serializable] attribute. Use the wpf data binding capabilities to control the CRUD operations of the data object. At this point, you can serialize and deserialize your data object using the XmlSerializer. On deserialization, bind your custom control to a data object and you're done.



Wish I had time to write a quick sample.

Hope it helps

+3


a source







All Articles