From 286ddb16415b359906dbee4f54fe838cf31fbc9a Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sun, 2 Aug 2015 07:11:16 +0200 Subject: [PATCH] Fix cloning of SettingsViewModels. --- .../SettingsRepositoryViewModelTest.cs | 1 + .../ViewModels/SettingsRepositoryViewModel.cs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) 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