private void TemplatesListBox_EditValueChanged(object sender, DevExpress.Xpf.Editors.EditValueChangedEventArgs e) { if (Stages != null && e.NewValue != null) { var sortIndex = Stages.Max(x => x.SortIndex) ?? 1; var template = (KeyValuePair <int, string>)e.NewValue; var newStage = new ProjectStageTile((EStageTemplate)template.Key, ++sortIndex); newStage.Project = _originalProject; Stages.Add(newStage); FocusedStage = newStage; StageTemplatesPopup.ClosePopup(); } }