/// <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 weatherViewModel = await WeatherDataServiceConsumer.GetWeatherInformation(App.ApplicationViewModel.SelectedLocation); App.ApplicationViewModel.CurrentWeatherInfo = weatherViewModel; this.DataContext = App.ApplicationViewModel; DisplayInformation.AutoRotationPreferences = DisplayOrientations.None; }
private async void TryAddCity(string cityName) { var cityInfo = await WeatherDataServiceConsumer.GetWeatherInformation(cityName); if (cityInfo != null) { App.ApplicationViewModel.SavedCities.Insert(1, cityName); } else { MessageDialog dialog = new MessageDialog("Cannot locate city", "Error"); await dialog.ShowAsync(); } this.SearchTextBox.Text = string.Empty; }
private void EnsureSettings() { if (ApplicationData.Current.LocalSettings.Values["SavedCities"] == null) { List <string> defaultCities = WeatherDataServiceConsumer.GetDefaultCities(); #if WINDOWS_PHONE_APP defaultCities.Insert(0, "CurrentLocation"); #endif ApplicationData.Current.LocalSettings.Values["SavedCities"] = defaultCities.ToArray(); } if (ApplicationData.Current.LocalSettings.Values["Units"] == null) { ApplicationData.Current.LocalSettings.Values["Units"] = "Metric"; } if (ApplicationData.Current.LocalSettings.Values["SelectedLocation"] == null) { #if WINDOWS_PHONE_APP ApplicationData.Current.LocalSettings.Values["SelectedLocation"] = "CurrentLocation"; #else ApplicationData.Current.LocalSettings.Values["SelectedLocation"] = "Sofia"; #endif } ApplicationViewModel = new ApplicationViewModel(); ApplicationViewModel.SavedCities = new ObservableCollection <string>(ApplicationData.Current.LocalSettings.Values["SavedCities"] as string[]); #if WINDOWS_PHONE_APP if (!ApplicationViewModel.SavedCities.Contains("CurrentLocation")) { ApplicationViewModel.SavedCities.Insert(0, "CurrentLocation"); } else { ApplicationViewModel.SavedCities.Remove("CurrentLocation"); ApplicationViewModel.SavedCities.Insert(0, "CurrentLocation"); } #endif ApplicationViewModel.MeasurementUnits = ApplicationData.Current.LocalSettings.Values["Units"].Equals("Metric") ? MeasurementUnits.Metric : MeasurementUnits.Imperial; ApplicationViewModel.SelectedLocation = (string)ApplicationData.Current.LocalSettings.Values["SelectedLocation"]; }
private async void RefreshWeatherInfo(bool forceRefresh = false) { if (Window.Current.Dispatcher != null) { await Window.Current.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async() => { IsBusy = true; try { var weatherinfo = await WeatherDataServiceConsumer.GetWeatherInformation(this.selectedLocation, forceRefresh); this.CurrentWeatherInfo = weatherinfo; } catch { MessageDialog dialog = new MessageDialog("Service unavailable", "Error"); dialog.ShowAsync(); } }); } }