/// <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) { if (e.PageState != null) { QueryText = (string)e.PageState["QueryText"]; if (e.PageState.ContainsKey("Results")) { var results = (string)e.PageState["Results"]; QueryTask = null; Results = JsonConvert.DeserializeObject <List <ExtendedBookItem> >(results); LoadResultIntoView(); } else { Results = null; QueryTask = null; } } else { QueryText = e.NavigationParameter as String; } if (Results == null && QueryTask == null) { VisualStateManager.GoToState(this, "Searching", false); QueryTask = DmzjDocSecBase.SearchBookAsync(QueryText); } // TODO: Application-specific searching logic. The search process is responsible for // creating a list of user-selectable result categories: // // filterList.Add(new Filter("<filter name>", <result count>)); // // Only the first filter, typically "All", should pass true as a third argument in // order to start in an active state. Results for the active filter are provided // in Filter_SelectionChanged below. var filterList = new List <Filter>(); filterList.Add(new Filter("All", 0, true)); this.DefaultViewModel["Filters"] = filterList; // Communicate results through the view model this.DefaultViewModel["ShowFilters"] = filterList.Count > 1; if (QueryTask != null) { try { Results = await QueryTask; } catch (Exception) { Results = null; } LoadResultIntoView(); } }
private async Task SearchForResultAsync() { if (QueryTask != null) { QueryTask.AsAsyncAction().Cancel(); } VisualStateManager.GoToState(this, "Searching", false); QueryTask = DmzjDocSecBase.SearchBookAsync(QueryText); try { Results = await QueryTask; } catch (Exception) { Results = null; } QueryTask = null; LoadResultIntoView(); }