/// <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) { _queryText = e.NavigationParameter as String; // Fetch the serach results from JobsDataSource var searchResults = await JobDataSource.SearchJobsBySearchTextAsync(_queryText); // Add the counts for various job status int countOnSite = searchResults.Count(item => item.Status == "On Site"); int countNotStarted = searchResults.Count(item => item.Status == "Not Started"); int countCompleted = searchResults.Count(item => item.Status == "Completed"); // Add the filters based upon the job status var filterList = new List <Filter>(); filterList.Add(new Filter("All", searchResults.Count, true)); if (countOnSite > 0) { filterList.Add(new Filter("On Site", countOnSite, false)); } if (countNotStarted > 0) { filterList.Add(new Filter("Not Started", countNotStarted, false)); } if (countCompleted > 0) { filterList.Add(new Filter("Completed", countCompleted, false)); } // Communicate results through the view model this.DefaultViewModel["QueryText"] = " " + '\u201c' + _queryText + '\u201d'; this.DefaultViewModel["Filters"] = filterList; this.DefaultViewModel["ShowFilters"] = filterList.Count > 0; this.DefaultViewModel["Results"] = searchResults; }
/// <summary> /// Invoked when a filter is selected using a RadioButton when not snapped. /// </summary> /// <param name="sender">The selected RadioButton instance.</param> /// <param name="e">Event data describing how the RadioButton was selected.</param> async void Filter_Checked(object sender, RoutedEventArgs e) { var filter = (sender as FrameworkElement).DataContext; // Mirror the change into the CollectionViewSource. // This is most likely not needed. if (filtersViewSource.View != null) { filtersViewSource.View.MoveCurrentTo(filter); } // Determine what filter was selected var selectedFilter = filter as Filter; if (selectedFilter != null) { // Mirror the results into the corresponding Filter object to allow the // RadioButton representation used when not snapped to reflect the change selectedFilter.Active = true; // Load the search results and filter them based on user-selected filter value _searchResults = await JobDataSource.SearchJobsBySearchTextAsync(_queryText); _searchResults = (selectedFilter.Name.Equals("All")) ? _searchResults : new List <Job>(_searchResults.Where(job => job.Status.Equals(selectedFilter.Name)).ToList()); this.DefaultViewModel["Results"] = _searchResults; // Ensure results are found object results; ICollection resultsCollection; if (this.DefaultViewModel.TryGetValue("Results", out results) && (resultsCollection = results as ICollection) != null && resultsCollection.Count != 0) { VisualStateManager.GoToState(this, "ResultsFound", true); return; } } // Display informational text when there are no search results. this.DefaultViewModel["ShowFilters"] = false; VisualStateManager.GoToState(this, "NoResultsFound", true); }