Example #1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    var postion = await ApiHandle.GetPosition();

#pragma warning disable CS0618 // Type or member is obsolete
                    var lat = postion.Coordinate.Latitude;
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
                    var lon = postion.Coordinate.Longitude;
#pragma warning restore CS0618 // Type or member is obsolete

                    OpenWeatherMap.RootObject forecast = await ApiHandle.GetWeather(lat, lon);

                    CityTextBlock.Text = forecast.city.name;

                    for (int i = 0; i < forecast.list.Count; i++)
                    {
                        //collection.Add(forecast.list[i]);
                        for (int j = 0; j < forecast.list[i].weather.Count; j++)
                        {
                            string icon        = string.Format("ms-appx:///Assets/Weather/{0}.png", forecast.list[i].weather[j].icon);
                            var    listReplace = forecast.list[i].weather[j];
                            listReplace.icon = icon;
                        }
                        collection.Add(forecast.list[i]);
                    }

                    ForeCastGridView.ItemsSource = collection;
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
        }