ViewModelLocator.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. In App.xaml:
  3. <Application.Resources>
  4. <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:Editor.ViewModel"
  5. x:Key="Locator" />
  6. </Application.Resources>
  7. In the View:
  8. DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
  9. */
  10. using GalaSoft.MvvmLight;
  11. using GalaSoft.MvvmLight.Ioc;
  12. using Microsoft.Practices.ServiceLocation;
  13. using Editor.Model;
  14. namespace Editor.ViewModel
  15. {
  16. /// <summary>
  17. /// This class contains static references to all the view models in the
  18. /// application and provides an entry point for the bindings.
  19. /// <para>
  20. /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
  21. /// to this locator.
  22. /// </para>
  23. /// <para>
  24. /// See http://www.galasoft.ch/mvvm/getstarted
  25. /// </para>
  26. /// </summary>
  27. public class ViewModelLocator
  28. {
  29. static ViewModelLocator()
  30. {
  31. ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
  32. SimpleIoc.Default.Register<IDataService, DataService>();
  33. SimpleIoc.Default.Register<MainViewModel>();
  34. }
  35. /// <summary>
  36. /// Gets the Main property.
  37. /// </summary>
  38. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
  39. "CA1822:MarkMembersAsStatic",
  40. Justification = "This non-static member is needed for data binding purposes.")]
  41. public MainViewModel Main
  42. {
  43. get
  44. {
  45. return ServiceLocator.Current.GetInstance<MainViewModel>();
  46. }
  47. }
  48. /// <summary>
  49. /// Cleans up all the resources.
  50. /// </summary>
  51. public static void Cleanup()
  52. {
  53. }
  54. }
  55. }