Exemplo n.º 1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    var postion = await LocationData.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

                    OpenWeatherMap5days.RootObject forecast = await ApiHandle.GetWeatherFiveDay(lat, lon);

                    CityTextBlock.Text = forecast.city.name;

                    for (int i = 0; i < forecast.list.Count; 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);
            }
        }