MVVM and SettingsBase
Hi i'm currently implement MVVM in a WPF app i'm developing. I implemented the ViewModel and the Views by using 2 separate projects. Only the View is referencing from the ViewModel. However, i've come to a point where i need the information in the Settings class(auto generated by Visual Studio using the Settings dialogue in the Project's Properties) to the ViewModel. How do i do that since Vi开发者_JAVA技巧ewModel shouldn't reference the View's classes and also Settings class has a internal modifier.
need your suggestions on this one...i'm using mvvm-light which has the Locator pattern..
thanks
Create an interface like this:
public interface IUserSettingsService
{
string FooSetting { get; }
bool BarSetting { get; }
}
Create an implementation of this service that will return values from the Settings class in your views project and register it in the service locator.
Then, in your view models project you can get it via the service locator. Something like this:
var mySettings = ServiceLocator.Instance.GetService<IUserSettingsService>();
精彩评论