public void DeleteCity(City city) { int count = 0; foreach (City c in App.Cities) { if (c.Id == city.Id) { break; } count++; } if (city.IsMyCity == true) { App.Cities.RemoveAt(count); if (App.Cities.Count > 0) { App.Cities[0].IsMyCity = true; } } else { App.Cities.RemoveAt(count); } }
private async void LoadCityForecast(City city) { NowViewModel vm = new NowViewModel(); await vm.GetForecast(city.Id); Label labelCityName = new Label(); labelCityName.Text = city.Name; ListView listViewForecast = new ListView(); listViewForecast.ItemTemplate = new DataTemplate(() => { Label labelData = new Label(); labelData.SetBinding(Label.TextProperty, "Dia"); Label labelMaxima = new Label(); labelMaxima.SetBinding(Label.TextProperty, "Maxima"); Label labelMinima = new Label(); labelMinima.SetBinding(Label.TextProperty, "Minima"); return new ViewCell { View = new StackLayout { Padding = new Thickness(0, 5), Orientation = StackOrientation.Horizontal, Children = { labelData, labelMaxima, labelMinima } } }; }); listViewForecast.BindingContext = vm.Forecasts; this.Content = new StackLayout { Children = { labelCityName, listViewForecast } }; listViewForecast.ItemsSource = vm.Forecasts; }
public void SetCityAsMyCity(City city) { foreach (City c in App.Cities) { if (c.Id == city.Id) { c.IsMyCity = true; } else { c.IsMyCity = false; } } }