protected void Edit(T item) { if (item == null) { item = new T(); } selectedItem = item; var vm = CreateViewModel(item); var window = CreateWindow(vm); window.ShowDialog(); if (vm.IsCancelled || item.Equals(vm.Setting)) { return; } var index = SettingCollection.IndexOf(item); if (index >= 0) { Remove(item); SettingCollection.Insert(index, vm.Setting); } else { SettingCollection.Add(vm.Setting); } IsDirty = true; }