/// <summary> /// Populate the list of checkboxes with teams' names, /// And check the teams that are selected /// </summary> private void PopulateTeamsComboboxes() { CheckListItems.Clear(); //Get all team features from the layer List <client.Graphic> allTeams = new List <client.Graphic>(teamFeatureLayer.Graphics); //Listen to the property change event of each feature. Particularly, we will listen to the "Selected" property foreach (client.Graphic team in allTeams) { team.PropertyChanged += team_PropertyChanged; } //Sort the names of all the teams for better presentation List <string> allTeamNames = allTeams.Select(t => t.Attributes[nameAttribute].ToString()).ToList(); allTeamNames.Sort(); //populate the check list items foreach (string teamName in allTeamNames) { MyCheckedListItem checkListItem = new MyCheckedListItem() { Caption = teamName, IsChecked = recommendedTeams.Any(selectedTeam => selectedTeam.Attributes[nameAttribute].ToString() == teamName) }; CheckListItems.Add(checkListItem); } }
/// <summary> /// When user selects/unselects a team feature on map, check/uncheck the corresponding check box on the team assignment page /// </summary> void team_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "Selected") { client.Graphic team = sender as client.Graphic; MyCheckedListItem checkListItem = CheckListItems.FirstOrDefault(item => item.Caption == team.Attributes[nameAttribute].ToString()); checkListItem.IsChecked = team.Selected; } }