private void ShowForecastedWeather(XmlDocument doc) { bool metric = Settings.WeatherMetric; XmlNodeList nodes = doc.GetElementsByTagName("time"); DateTime current = DateTime.Now.Date; int count = -1; for (int i = 0; i < nodes.Count && i < 16; i++) { XmlNode each = nodes[i]; DateTime _date = DateTime.Parse(each.Attributes["day"].Value); if (_date >= current) { count++; string _skyCondition = each["symbol"].Attributes["number"].Value; XmlElement temp = each["temperature"]; string _temperature = Math.Round(metric ? WeatherFunctions.KelvinToCelsius(double.Parse(temp.Attributes["max"].Value)) : WeatherFunctions.KelvinToFarenheit(double.Parse(temp.Attributes["max"].Value)) ).ToString() + "° / " + Math.Round(metric ? WeatherFunctions.KelvinToCelsius(double.Parse(temp.Attributes["min"].Value)) : WeatherFunctions.KelvinToFarenheit(double.Parse(temp.Attributes["min"].Value)) ).ToString() + "°"; string _pressure = WeatherFunctions.FormatDouble(metric ? double.Parse(each["pressure"].Attributes["value"].Value) : WeatherFunctions.MillibarToInHg(double.Parse(each["pressure"].Attributes["value"].Value) ), 1) + (metric ? " hPa" : " in"); string _humidity = each["humidity"].Attributes["value"].Value + " %"; string _cloudPercent = each["clouds"].Attributes["all"].Value + " %"; string _wind = each["windDirection"].Attributes["code"].Value + " " + WeatherFunctions.FormatDouble( metric ? WeatherFunctions.MpsToKmH(double.Parse(each["windSpeed"].Attributes["mps"].Value)) : WeatherFunctions.MpsToMph(double.Parse(each["windSpeed"].Attributes["mps"].Value) ), 1) + (metric ? " km/h" : " mph"); XmlAttribute precip = each["precipitation"].Attributes["value"]; string _precipitation; if (precip != null) { _precipitation = WeatherFunctions.FormatDouble(metric ? double.Parse(precip.Value) / 10 : WeatherFunctions.MmToIn(double.Parse(precip.Value) ), 1) + (metric ? " cm" : " in"); } else { _precipitation = metric ? "0.0 cm" : "0.0 in"; } Dispatcher.Invoke(() => { ForecastControl fc = (ForecastControl)forecastBox.Children[count]; fc.Visibility = Visibility.Visible; fc.Date = _date; fc.SkyCondition = _skyCondition; fc.Temperature = _temperature; fc.Pressure = _pressure; fc.Humidity = _humidity; fc.CloudPercent = _cloudPercent; fc.Wind = _wind; fc.Precipitation = _precipitation; }); } } Dispatcher.Invoke(() => { // Handle just in case the weather service doesn't give us // the full 16-day forecast. (Yes, this has actually happened.) for (int i = count + 1; i < 16; i++) { UIElement fc = forecastBox.Children[i]; fc.Visibility = Visibility.Collapsed; } if (forecastBox.Children[0].Visibility == Visibility.Collapsed) { noForecastText.Visibility = Visibility.Visible; } else { noForecastText.Visibility = Visibility.Collapsed; } UpdateTimeFormat(); }); }