Fix cloning of SettingsViewModels.

This commit is contained in:
Daniel Kraus 2015-08-02 07:11:16 +02:00
parent d0be7524d3
commit 286ddb1641
2 changed files with 16 additions and 3 deletions

View File

@ -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);
}
}
}

View File

@ -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
}
}
/// <summary>
/// Adds a settings view model to the collection and wires the
/// PropertyChanged event.
/// </summary>
/// <param name="settingsViewModel">SettingsViewModel to add.</param>
void AddSettingsViewModel(SettingsViewModel settingsViewModel)
{
settingsViewModel.PropertyChanged += SettingsViewModel_PropertyChanged;
SettingsList.Add(settingsViewModel);
}
#endregion
#region Implementation of ViewModelBase