A static class, as Phil mentions, is a great idea, but I would suggest exploring the use of dependency injection. You may not need a full IoC container, but this will probably help you in your scenario. Caliburn.Micro integrates such a container very easily.
Create the Settings
class. (I would also create an ISettings
interface ISettings
that you can pass the stub settings to your view models for testing, but this is an added bonus.) Then make all your ViewModels the necessary instance of ISettings
in your constructors.
When your application starts, you create one instance of Settings
that reads from IsolStorage or wherever you are, then pass that instance to any CreateModel created.
This Settings
class may be responsible for saving settings back to IsolStorage whenever necessary.
An example of this scenario:
In the AppBootstrapper
class:
PhoneContainer container; ISettings settings; protected override void Configure() {
In your ViewModel class:
ISettings settings; public MainPageViewModel(ISettings settings) { this.settings = settings; }
At this point, you will have all your settings for your ViewModel.
source share