| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /*
- In App.xaml:
- <Application.Resources>
- <vm:ViewModelLocator xmlns:vm="clr-namespace:MuchInfo.Chart.App.ViewModels"
- x:Key="Locator" />
- </Application.Resources>
-
- In the View:
- DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
- */
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Ioc;
- using Microsoft.Practices.ServiceLocation;
- using MuchInfo.Chart.App.Services;
- namespace MuchInfo.Chart.App.ViewModels
- {
- /// <summary>
- /// This class contains static references to all the view models in the
- /// application and provides an entry point for the bindings.
- /// <para>
- /// See http://www.galasoft.ch/mvvm
- /// </para>
- /// </summary>
- public class ViewModelLocator
- {
- static ViewModelLocator()
- {
- ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
- //注册服务
- if (ViewModelBase.IsInDesignModeStatic)
- {
- //in Blend
- // SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
- }
- else
- {
- //In Visual Studio
- // SimpleIoc.Default.Register<IDataService, DataService>();
- SimpleIoc.Default.Register<IDataService, DataService>();
- }
- SimpleIoc.Default.Register<MainViewModel>();
- }
- /// <summary>
- /// Gets the Main property.
- /// </summary>
- public MainViewModel Main
- {
- get
- {
- return ServiceLocator.Current.GetInstance<MainViewModel>();
- }
- }
- }
- }
|