/// <summary> /// Checks if 'search' and 'countryId' parameters exist /// If 'search' exists, get the filtered results /// If 'countryId' exists, get the data for the corresponding country /// </summary> /// <param name="e"></param> protected async override void OnNavigatedTo(NavigationEventArgs e) { listbox.Opacity = 0; textBoxSearch.Text = String.Empty; textBoxSearch.Visibility = System.Windows.Visibility.Collapsed; if (NavigationContext.QueryString.ContainsKey("search")) { sortCounter = 0; string searchTerm = NavigationContext.QueryString["search"]; CityModel cm = new CityModel() { Cities = model.Cities.Where(x => x.Name.Contains(searchTerm)).ToList() }; DataContext = cm; if (isMapVisible) { map.Visibility = System.Windows.Visibility.Visible; SetMapCenter(true); } } else if (NavigationContext.QueryString.ContainsKey("countryId")) { SystemTray.ProgressIndicator = new ProgressIndicator(); ProgressIndicatorHelper.SetProgressBar(true, AppResources.ProgressIndicatorCities); //get id for retrieving country data int selectedCountryId = Int32.Parse(NavigationContext.QueryString["countryId"]); //get the value which will help to determine if map was visible or not isMapVisible = bool.Parse(NavigationContext.QueryString["mapVisible"]); cityCoordinates = new double[2]; //countryCoordinates = new double[2]; //double.TryParse(NavigationContext.QueryString["lat"], out countryCoordinates[0]); //double.TryParse(NavigationContext.QueryString["lon"], out countryCoordinates[1]); //Get the CityData based on selectedCountryId model = new CityModel() { Cities = await App.MobileService.GetTable<CityData>(). Where(x => x.CountryId == selectedCountryId).ToListAsync() }; //find index of city with highest rating int index = 0; float temp = model.Cities[index].Rating; for (int i = 1; i < model.Cities.Count; i++) { if (model.Cities[i].Rating > temp) { temp = model.Cities[i].Rating; index = i; } } //find geocoordinates of the city with highest rating FindGeoCoordinates(model.Cities[index].Name); //if map was visible, set it visible and center it to selected country coordinates if (isMapVisible) map.Visibility = System.Windows.Visibility.Visible; DataContext = model; ProgressIndicatorHelper.SetProgressBar(false, null); } AnimationHelper.Fade(listbox, 1, 700, new PropertyPath(OpacityProperty)); }
/// <summary> /// Sorts the city list by highest rating, and alphabetically (both ascending and descending) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sortIconButton_Click(object sender, EventArgs e) { if (sortCounter == 0) DataContext = new CityModel() { Cities = (DataContext as CityModel). Cities.OrderByDescending(x => x.Rating).ToList() }; else if (sortCounter == 1) DataContext = new CityModel() { Cities = (DataContext as CityModel). Cities.OrderByDescending(x => x.Name).ToList() }; else DataContext = new CityModel() { Cities = (DataContext as CityModel). Cities.OrderBy(x => x.Name).ToList() }; sortCounter += 1; if (sortCounter == 3) sortCounter = 0; }