private void FindControls(Disease d) { lblNoControls.Visibility = Visibility.Hidden; LoadedControls.Clear(); List <int> controlIds = d.ControlIds.ToList(); foreach (Control c in Controls) { if (controlIds.Contains(c.ControlId)) { LoadedControls.Add(c); } } labelControls.Content = d.Name + ": Controls (" + LoadedControls.Count + ")"; if (LoadedControls.Count == 0) { lblNoControls.Visibility = Visibility.Visible; } }
private void buttonControlDelete_Click(object sender, RoutedEventArgs e) { if (listControls.SelectedIndex == -1) { return; } MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this control?", "Are you sure?", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { int index = listControls.SelectedIndex; Control c = LoadedControls.ElementAt(index); Disease d = Diseases.ElementAt(listDiseases.SelectedIndex); Controls.Remove(c); LoadedControls.Remove(c); List <int> clist = d.ControlIds.ToList(); clist.RemoveAt(index); d.ControlIds = clist; d.SaveAsync(); c.DeleteAsync(); FindControls(Diseases.ElementAt(listDiseases.SelectedIndex)); index--; if (index < 0) { index = 0; } if (LoadedControls.Count > 0) { listControls.SelectedIndex = index; } MessageBox.Show("Control deleted."); } }