diff --git a/Tests/ViewModels/SettingsRepositoryViewModelTest.cs b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs index 2adb414..ff434a1 100755 --- a/Tests/ViewModels/SettingsRepositoryViewModelTest.cs +++ b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs @@ -66,6 +66,7 @@ namespace Tests.ViewModels Assert.AreNotSame(orig.RevealModelObject(), copy.RevealModelObject()); Assert.AreEqual(String.Format("Kopie von {0}", orig.Name), copy.Name); + Assert.IsTrue(copy.IsSelected); } } } diff --git a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs index 24ea5b1..11a764b 100755 --- a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs @@ -182,8 +182,7 @@ namespace zaaReloaded2.ViewModels foreach (Settings s in repository.SettingsList) { SettingsViewModel vm = new SettingsViewModel(s); - vm.PropertyChanged += SettingsViewModel_PropertyChanged; - SettingsList.Add(vm); + AddSettingsViewModel(vm); } } @@ -268,8 +267,10 @@ namespace zaaReloaded2.ViewModels if (Selected != null) { SettingsViewModel copy = Selected.Clone() as SettingsViewModel; - SettingsList.Add(copy); _repository.SettingsList.Add(copy.RevealModelObject() as Settings); + AddSettingsViewModel(copy); + Selected.IsSelected = false; + copy.IsSelected = true; } } @@ -300,6 +301,17 @@ namespace zaaReloaded2.ViewModels } } + /// + /// Adds a settings view model to the collection and wires the + /// PropertyChanged event. + /// + /// SettingsViewModel to add. + void AddSettingsViewModel(SettingsViewModel settingsViewModel) + { + settingsViewModel.PropertyChanged += SettingsViewModel_PropertyChanged; + SettingsList.Add(settingsViewModel); + } + #endregion #region Implementation of ViewModelBase