Tell me how to serialize a class with a collection of the type ObservableCollection`?
Trying to do on class Example .
public class Animal { public string Sound { get; set; } } [Serializable] public class Example { public string Properties1 { get; set; } = "nothing"; public bool Properties2 { get; set; } public static ObservableCollection<Animal> MyCollection { get; set; } = new ObservableCollection<Animal>(); public Example() { MyCollection.Add(new Animal() { Sound = "Мяу"}); MyCollection.Add(new Animal() { Sound = "Гав" }); } } I serialize it, but only the properties are serialized:
Example example = new Example(); XmlSerializer formatter = new XmlSerializer(typeof(Example)); using (FileStream fs = new FileStream("test.xml", FileMode.OpenOrCreate)) { formatter.Serialize(fs, example); }