private void AddRadioGroupMenuItem_Click(object sender, RoutedEventArgs e) { if (_viewModel.SelectedElement == null) { return; } if (!(_viewModel.SelectedElement is CombinedElementViewModel combined)) { MessageBox.Show($"Selected Element: {_viewModel.SelectedElement.Name} is not nested from CombinedElementViewModel. But has to"); return; } var model = WebFactory.CreateRadioGroupModel(); var dialog = new WebElementDetailsWindow(model, combined.GetExistedNames(), false); if (dialog.ShowDialog() != true) { return; } var rgName = model.Name.Replace("RadioGroup", "").Trim(); var option = model.Elements.First(el => el.InnerKey == RadioGroupElementInfo.Keys.Option); option.Name = $"{rgName} Option"; dialog = new WebElementDetailsWindow(option, model.GetExistedNames(), true); if (dialog.ShowDialog() != true) { return; } if (combined.Elements == null) { combined.Elements = new ObservableCollection <WebElementViewModel>(); } model.Parent = combined; combined.Elements.Add(model); _viewModel.SelectedElement = model; }