/// <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 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(); } }); } }