MVVM I have been learning the basics I have a basic Model and ViewModel setup not sure how to go from there.

I have my ViewModel and as you can see I dummied up an object to test with. I am unsure how I would normally do this. The variables will be loaded from a config file I read in on start. Using MVVM how would I load in a config file. Also I have several combo boxes I want to set the item source based on an xml file I read in. Should I put them in the Config View Model or what would be the best way to handle it?

I think I should create a second model for the combo box item sources and put that in the Config View Model. Just wanted to make sure that was proper MVVM style and I wanted to get some help on how I would handle populating the variables and adding in the combo box observable collections.

class ConfigViewModel { ConfigModel _conMod;

 public ConfigViewModel() { _conMod = new ConfigModel { EnviromentNum = 1, EnviromentName = "Production", Browser = "IE", NumDevices = 1, TestFile = "Test.CSV" }; } public ConfigModel ConfigModel { get { return _conMod; } set { _conMod = value; } } public int EnviromentNum { get { return _conMod.EnviromentNum; } set { if (_conMod.EnviromentNum != value) { _conMod.EnviromentNum = value; RaisePropertyChanged("EnviromentNum"); } } } public string EnviromentName { get { return _conMod.EnviromentName; } set { if (_conMod.EnviromentName != value) { _conMod.EnviromentName = value; RaisePropertyChanged("EnviromentName"); } } } public string Browser { get { return _conMod.Browser; } set { if (_conMod.Browser != value) { _conMod.Browser = value; RaisePropertyChanged("Browser"); } } } public int NumDevices { get { return _conMod.NumDevices; } set { if (_conMod.NumDevices != value) { _conMod.NumDevices = value; RaisePropertyChanged("NumDevices"); } } } public string TestFile { get { return _conMod.TestFile; } set { if (_conMod.TestFile != value) { _conMod.TestFile = value; RaisePropertyChanged("TestFile"); } } } public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged(string propertyName) { // take a copy to prevent thread issues PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } } 

by Mac_Attack18 via /r/csharp

Leave a Reply