private async void GetWeatherBtn_Clicked(object sender, EventArgs e) { if (!string.IsNullOrEmpty(zipCodeEntry.Text)) { if (zipCodeEntry.Text.Length != 5) { await DisplayAlert("Error", "Zip Code is invalid", "OK"); } else { string errors = await _weatherViewModel.GetWeather(zipCodeEntry.Text); if (!string.IsNullOrEmpty(errors)) { await DisplayAlert("", errors, "OK"); } } getWeatherBtn.Text = "Search Again"; } else { await DisplayAlert("Error", "Please enter a zip code", "OK"); } }
private void Start() { timer = new Timer(RefreshInterval); timer.Elapsed += async delegate { try { await Dispatcher.InvokeAsync(new Action(() => { viewModel.GetWeather(); })); } catch (TaskCanceledException e) { Console.Write(e.Message); } }; timer.Enabled = true; }
public WeatherApplet() { InitializeComponent(); viewModel = this.DataContext as WeatherViewModel; // Workaround to attach location and units properties in viewModel to dynamic resources of application. //this.SetResourceReference(WeatherApplet.LocationProperty, "Location"); //this.SetResourceReference(WeatherApplet.UnitsProperty, "Units"); this.Loaded += async delegate { await viewModel.GetWeather(); }; Application.Current.Resources["FirstLoadCommand"] = new RelayCommand(o => { WeatherDisplay.Visibility = System.Windows.Visibility.Visible; WeatherAppletContent.Children.Remove(InitialProgressRing); RefreshWeatherButton.IsEnabled = true; Start(); }); }
private async void OnWeatherTap(object sender, EventArgs args) { WeatherViewModel weatherViewModel = new WeatherViewModel(); //var locator = CrossGeolocator.Current; //locator.DesiredAccuracy = 50; //var location = await locator.GetPositionAsync(TimeSpan.FromTicks(10000)); //if (location != null && location.Latitude != 0) //{ // await weatherViewModel.GetWeather(location.Latitude, location.Longitude); //} //else { //MYSORE //await weatherViewModel.GetWeather("12.311827", "76.652985"); //BRISBANE await weatherViewModel.GetWeather("-27.470125", "153.021072"); } await Navigation.PushAsync(new WeatherPage()); }