| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /*
- In App.xaml:
- <Application.Resources>
- <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:Editor.ViewModel"
- 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 Editor.Model;
- namespace Editor.ViewModel
- {
- /// <summary>
- /// This class contains static references to all the view models in the
- /// application and provides an entry point for the bindings.
- /// <para>
- /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
- /// to this locator.
- /// </para>
- /// <para>
- /// See http://www.galasoft.ch/mvvm/getstarted
- /// </para>
- /// </summary>
- public class ViewModelLocator
- {
- static ViewModelLocator()
- {
- ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
- if (ViewModelBase.IsInDesignModeStatic)
- {
- SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
- }
- else
- {
- SimpleIoc.Default.Register<IDataService, DataService>();
- }
- SimpleIoc.Default.Register<MainViewModel>();
- }
- /// <summary>
- /// Gets the Main property.
- /// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
- "CA1822:MarkMembersAsStatic",
- Justification = "This non-static member is needed for data binding purposes.")]
- public MainViewModel Main
- {
- get
- {
- return ServiceLocator.Current.GetInstance<MainViewModel>();
- }
- }
- /// <summary>
- /// Cleans up all the resources.
- /// </summary>
- public static void Cleanup()
- {
- }
- }
- }
|