In my WPF MVVM
application, I have Model
, View
, and ViewModel
as a separate projects. Now, in my View
application I have user settings defined in Settings.settings
file, I can access them through:
Properties.Settings.Default.MySettingName
and in my Tool.exe.xml I can confirm that the setting is there:
<userSettings>
<Tool.Properties.Settings>
<setting name="MySettingName" serializeAs="String">
<value>False</value>
</setting>
</Tool.Properties.Settings>
</userSettings>
Now the question is how do I access those settings from my ViewModel project?
It's obvious that if I were to do Properties.Settings.Default.*
it will point to it's own settings.
So far I tried to do the following two ways:
Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationCollection settings = configFile.AppSettings.Settings;
and
var keys = ConfigurationManager.AppSettings.AllKeys;
But both of them always return 0 entities.
I also know that I can create a ViewModel
and bind settings from the View, but for this particular case, creating a new ViewModel
just to access setings sounds a little bit overkill.
Thanks for help!