| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /*
- 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);
- 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()
- {
- }
- }
- }
|