示例#1
0
        private void MenuItem_Export(object sender, RoutedEventArgs e)
        {
            XmlSerializer  SerializerObj  = new XmlSerializer(MoviesList.GetType());
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt = ".xml";
            saveFileDialog.Filter     = "XML documents (.xml) |*.xml";

            Nullable <bool> result = saveFileDialog.ShowDialog();

            if (result == true)
            {
                var          path = saveFileDialog.FileName;
                StreamWriter wr   = new StreamWriter(path);
                SerializerObj.Serialize(wr, MoviesList);
            }
        }
示例#2
0
        private void MenuItem_Import(object sender, RoutedEventArgs e)
        {
            XmlSerializer  SerializerObj  = new XmlSerializer(MoviesList.GetType());
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.DefaultExt = ".xml";
            openFileDialog.Filter     = "XML documents (.xml) |*.xml";

            Nullable <bool> result = openFileDialog.ShowDialog();

            if (result == true)
            {
                var          path = openFileDialog.FileName;
                StreamReader rd   = new StreamReader(path);
                ObservableCollection <Movie> list = new ObservableCollection <Movie>();

                list = (ObservableCollection <Movie>)SerializerObj.Deserialize(rd);
                foreach (Movie item in list)
                {
                    MoviesList.Add(item);
                }
            }
        }