private async Task LoadWeatherImage(string cityName) { var weather = await APIProcessor.LoadWeatherIcon(cityName); string path = string.Format("http://openweathermap.org/img/wn/{0}@2x.png", weather.Weather[0].icon); WeatherImage.Load(path); int temperature = Convert.ToInt32(weather.Main.Temp - 273.15); DegreeLabel.Text = temperature.ToString() + "°C"; }
public WeatherDetailPage() { InitializeComponent(); ViewModel = new WeatherDetailViewModel(); BindingContext = ViewModel; DescriptionLabel.SetBinding(Label.TextProperty, nameof(ViewModel.Description)); CurrentTemperatureLabel.SetBinding(Label.FormattedTextProperty, nameof(ViewModel.CurrentTemperatureFormatted), converter: new TemperatureFormatterConverter()); HighAndLowTemperatureLabel.SetBinding(Label.TextProperty, nameof(ViewModel.HighAndLowTemperatureFormatted)); WeatherImage.SetBinding(Image.SourceProperty, nameof(ViewModel.BackgroundPath)); SetBinding(Page.TitleProperty, new Binding(nameof(ViewModel.CityName))); }
/// <summary> /// Gets the Weather Date and Stores into x. /// Updates Temprature & Weather Icon As per results. /// </summary> public async void Updater(bool FormLoaded) { //if (darkSky.ApiCallsMade.Value <= 3) { try { if (CityChanged || FormLoaded) { FormLoaded = false; CityChanged = false; #region Getting Lat & Lon after Selection //Making Sure the xml is Embedded Resource and Path will be automatically relevant. //Also Check for Properties Panel for the xml File. xmlDocument.Load("Cities.xml"); //getting the Latitude and Longitude XmlNode node = xmlDocument.SelectSingleNode(String.Format("/Cities/name[{0:0}]/lat", Properties.Settings.Default.City)); latitude = Convert.ToDouble(node.InnerText); node = xmlDocument.SelectSingleNode(String.Format("/Cities/name[{0:0}]/lon", Properties.Settings.Default.City)); longitude = Convert.ToDouble(node.InnerText); node = xmlDocument.SelectSingleNode(String.Format("/Cities/name[{0:0}]/name", Properties.Settings.Default.City)); City = node.InnerText; node = xmlDocument.SelectSingleNode(String.Format("/Cities/name[{0:0}]/state", Properties.Settings.Default.City)); State = node.InnerText; #endregion } //Setting Window Opacity From settings WindowClock.Opacity = Properties.Settings.Default.Opacity; //Setting ComboBox Index CityComboBox.SelectedIndex = Properties.Settings.Default.City - 1; //Initialisation and Connection to the Weather Api. x = await darkSky.GetWeatherDataAsync(latitude, longitude, unit); TxtTemprature.BeginAnimation(OpacityProperty, Anims.RevAnim); TxtTemprature.Text = (x.Currently.Temperature.ToString() + " °C"); TxtTempratureLow.Text = (x.Currently.ApparentTemperature.ToString()); switch (x.Currently.Icon) { case "clear-day": WeatherIcon = "Images\\sun.png"; break; case "clear-night": WeatherIcon = "Images\\013-moon.png"; break; case "rain": WeatherIcon = "Images\\012-raining.png"; break; case "wind": WeatherIcon = "Images\\004-wind-1.png"; break; case "partly-cloudy-day": case "partly-cloudy-night": case "cloudy": WeatherIcon = "Images\\Cloudy.png"; break; case "thunderstorm": WeatherIcon = "Images\\006-storm-1.png"; break; default: WeatherIcon = "Images\\sun.png"; break; } TxtCity.Text = City; TxtState.Text = State; WeatherImage.BeginAnimation(OpacityProperty, Anims.FrwdAnim); WeatherImage.Source = new BitmapImage(new Uri(WeatherIcon, UriKind.Relative)); WeatherImage.BeginAnimation(OpacityProperty, Anims.RevAnim); TxtDate.Text = DateTime.Now.ToString("dd MMMM yyyy"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }