/// <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)
        {
            if (e.PageState != null && e.PageState.ContainsKey("CurrentSite"))
            {
                var result = await StringIOExtensions.ReadFromFile("data.txt");
                ServiceManager.Sites = await JsonConvert.DeserializeObjectAsync<ObservableCollection<SiteModel>>(result);
                var ds = this.DataContext as SiteViewModel;
                if (ds != null)
                {
                    await ds.LoadData(e.PageState["CurrentSite"].ToString(), null);
                    if (e.PageState.ContainsKey("SelectedIndex"))
                    {
                        ds.CurrentSite.SelectedIndex = e.PageState["SelectedIndex"].ToInt();
                        PnlPivot_OnLoaded(null,null);
                    }
                }
                e.PageState["CurrentSite"] = null;
                e.PageState["SelectedIndex"] = null;
            }
            else
            {
                var ds = DataContext as SiteViewModel;
                if (ds != null)
                {
                    await ds.LoadData(e.NavigationParameter.ToString(), null);
                }
            }

        }
        /// <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 clickedItem = (ItemModel) e.NavigationParameter;
            var group = await ServiceManager.GetPageAsync(clickedItem.Parent.PageIndex);
            this.DefaultViewModel["Group"] = group;
            if (group != null)
            {
                this.DefaultViewModel["Items"] = group.Items;
            }
            this.DefaultViewModel["SelectedItem"] = clickedItem;

            if (e.PageState == null)
            {
                this.itemListView.SelectedItem = null;
                // When this is a new page, select the first item automatically unless logical page
                // navigation is being used (see the logical page navigation #region below.)
                if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null)
                {
                    this.itemsViewSource.View.MoveCurrentToFirst();
                }
            }
            else
            {
                // Restore the previously saved state associated with this page
                if (e.PageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null)
                {
                    var selectedItem = await SampleDataSource.GetItemAsync((String)e.PageState["SelectedItem"]);
                    this.itemsViewSource.View.MoveCurrentTo(selectedItem);
                }
            }
        }
 /// <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="navigationParameter">The parameter value passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
 /// </param>
 /// <param name="pageState">A dictionary of state preserved by this page during an earlier
 /// session.  This will be null the first time a page is visited.</param>
 private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     var ds = this.DataContext as SearchResultViewModel;
     if (ds != null)
     {
         ds.QueryText = e.NavigationParameter as String;
         await ds.LoadData();
     }
 }
        /// <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 titleDetailsViewModel = DataContext as SiteViewModel;
            //if (titleDetailsViewModel != null)
            //{
            //    var parameters = e.NavigationParameter as List<string>;
            //    if (parameters != null && parameters.Count == 2)
            //    {
            //        titleDetailsViewModel.LoadData(parameters[0], parameters[1]);
            //    }
            //}

            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            //var sampleDataGroups = await SampleDataSource.GetGroupsAsync();
            //this.DefaultViewModel["Items"] = sampleDataGroups;
        }
 /// <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 ds = DataContext as MainViewModel;
     if (ds != null)
     {
         await ds.LoadData(null);
     }
 }