private void btnOpen_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Address Book Binary File (*.adb)|*.adb|Address Book XML File (*.adbx)|*.adbx"; if (dialog.ShowDialog() ?? false) { FileInfo fi = new FileInfo(dialog.FileName); switch (fi.Extension) { case ".adb": using (FileStream fs = File.OpenRead(dialog.FileName)) { BinaryFormatter bf = new BinaryFormatter(); this.addressBook = (Model.AddressBook)bf.Deserialize(fs); } break; case ".adbx": using (XmlReader xr = XmlReader.Create(dialog.FileName)) { DataContractSerializer serializer = new DataContractSerializer(typeof(Model.AddressBook)); this.addressBook = (Model.AddressBook)serializer.ReadObject(xr); } break; } this.DataContext = this.addressBook; SetupAddressBookDefaultViewCollection(); } }
private void FillAddressBook(Model.AddressBook addressBook) { addressBook.Persons.Add(new Person() { Name = "Goran Urukalo", BirthDate = new DateTime(1996, 1, 15), Height = 196, Gender = Gender.Male }); addressBook.Persons[0].Addresses.Add(new Address { StreetName = "Isidora Stojanovica", StreetNumber = "84" }); addressBook.Persons.Add(new Person() { Name = "Mika Mikić", BirthDate = new DateTime(1885, 5, 15), Height = 185 }); }