private void changeHomeButton_Click(object sender, RoutedEventArgs e) { if (!NetworkInterface.GetIsNetworkAvailable()) { ShowNetworkDialog(); return; } ChangeLocationDialog dlg = new ChangeLocationDialog(true); dlg.Owner = Application.Current.MainWindow; if (dlg.ShowDialog() == true) { try { Location location = new Location(dlg.LocationReference); Settings.WeatherHome = (homePanel.Children[0] as Place).City = location.Locality + ", " + location.AdministrativeAreaLevel1 + ", " + location.Country; foreach (WeatherPeekContent each in WeatherPeekContent.LoadedWeatherPeekContents) { each.Refresh(); } } catch { ShowNetworkDialog(); } } }
private void addFavorite_Click(object sender, RoutedEventArgs e) { if (!NetworkInterface.GetIsNetworkAvailable()) { ShowNetworkDialog(); return; } ChangeLocationDialog dlg = new ChangeLocationDialog(false); dlg.Owner = Window.GetWindow(this); if (dlg.ShowDialog() == true) { try { Place p = new Place(); Location location = new Location(dlg.LocationReference); p.City = location.Locality + ", " + location.AdministrativeAreaLevel1 + ", " + location.Country; string[] favorites = Settings.WeatherFavorites; if (favorites != null) { string loc = p.City.ToLower(); foreach (string each in favorites) { if (each.ToLower() == loc) { TaskDialog td = new TaskDialog(Window.GetWindow(this), "Location is in use", "You already have " + p.City + " in your favorites.", MessageType.Error); td.ShowDialog(); return; } } } p.Click += Place_Click; favoritesPanel.Children.Insert(favoritesPanel.Children.Count - 1, p); if (favorites != null) { Array.Resize(ref favorites, favorites.Length + 1); favorites[favorites.Length - 1] = p.City; } else { favorites = new string[] { p.City } }; Settings.WeatherFavorites = favorites; } catch { ShowNetworkDialog(); } } }