private void ListView_ItemSelection(object sender, SelectionChangedEventArgs e) { var item = (sender as ListView).SelectedItem as Member; if (item != null) { Member = item as Member; MemberClubs = new ObservableCollection <Club>(); MemberSports = new ObservableCollection <Sport>(); Clubs.Clear(); Sports.Clear(); foreach (Sport s in AllSports) { Sports.Add(s); } foreach (Club club in Member.Clubs) { MemberClubs.Add(club); } foreach (Sport sport in Member.Sports) { MemberSports.Add(sport); foreach (Club c in sport.Clubs) { Clubs.Add(c); } } foreach (Club club in MemberClubs) { var filteredClub = Clubs.FirstOrDefault(c => c.Id == club.Id); Clubs.Remove(filteredClub); } foreach (Sport sport in MemberSports) { var filteredSport = AllSports.FirstOrDefault(s => s.Id == sport.Id); Sports.Remove(filteredSport); } } }
private void ListView_SportInSportsSelection(object sender, SelectionChangedEventArgs e) { var item = (sender as ListView).SelectedItem as Sport; if (item != null) { Sports.Remove(item); MemberSports.Add(item); Clubs.Clear(); foreach (Sport s in MemberSports) { foreach (Club c in s.Clubs) { Clubs.Add(c); } } foreach (Club club in MemberClubs) { var filteredClub = Clubs.FirstOrDefault(c => c.Id == club.Id); Clubs.Remove(filteredClub); } } }
private void OnDelete() { Sports.Remove(SelectedSport); }