Exemplo n.º 1
0
        private async void AppBarAddGroupButton_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new AddGroupDialog();
            var ret = await dlg.ShowAsync();

            if (ret == ContentDialogResult.Primary)
            {
                var group = await GetDataAsync(dlg.Message, dlg.Criterion);

                this.GroupsViewModel.Add(group);
                await XmlIO.SaveObjectToXml(this.GroupsViewModel.ToList(), "data.xml");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            //var dict = ApplicationData.Current.RoamingSettings.Values;
            //var data = dict["data"] as byte[];
            //if (data == null)
            //{
            //    var group = await SampleDataSource.GetGroupsAsync();
            //    this.DefaultViewModel["Groups"] = group;
            //}
            //else
            //{
            //    var x = new XmlSerializer(typeof(IEnumerable<SampleDataGroup>));
            //    using (var ms = new MemoryStream(data))
            //    {
            //        var group = x.Deserialize(ms) as IEnumerable<SampleDataGroup>;
            //        this.DefaultViewModel["Groups"] = group;
            //    }
            //}

            List <ContactGroup> data = null;

            try
            {
                data = await XmlIO.ReadObjectFromXmlFileAsync <List <ContactGroup> >("data.xml");
            }
            catch (FileNotFoundException)
            {
                Debug.WriteLine("file not found");
            }
            catch (InvalidOperationException)
            {
                Debug.WriteLine("format not right");
            }

            Debug.WriteLine(data);
            if (data == null)
            {
                //var group = await SampleDataSource.GetGroupsAsync();
                //this.DefaultViewModel["Groups"] = group.ToList();
            }
            else
            {
                this.GroupsViewModel.Clear();
                foreach (var item in data)
                {
                    this.GroupsViewModel.Add(item);
                }
            }
        }