ViewModelLocator.cs.pp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. In App.xaml:
  3. <Application.Resources>
  4. <vm:ViewModelLocator xmlns:vm="clr-namespace:$rootnamespace$"
  5. x:Key="Locator" />
  6. </Application.Resources>
  7. In the View:
  8. DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
  9. You can also use Blend to do all this with the tool's support.
  10. See http://www.galasoft.ch/mvvm
  11. */
  12. using GalaSoft.MvvmLight;
  13. using GalaSoft.MvvmLight.Ioc;
  14. using Microsoft.Practices.ServiceLocation;
  15. namespace $rootnamespace$.ViewModel
  16. {
  17. /// <summary>
  18. /// This class contains static references to all the view models in the
  19. /// application and provides an entry point for the bindings.
  20. /// </summary>
  21. public class ViewModelLocator
  22. {
  23. /// <summary>
  24. /// Initializes a new instance of the ViewModelLocator class.
  25. /// </summary>
  26. public ViewModelLocator()
  27. {
  28. ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
  29. ////if (ViewModelBase.IsInDesignModeStatic)
  30. ////{
  31. //// // Create design time view services and models
  32. //// SimpleIoc.Default.Register<IDataService, DesignDataService>();
  33. ////}
  34. ////else
  35. ////{
  36. //// // Create run time view services and models
  37. //// SimpleIoc.Default.Register<IDataService, DataService>();
  38. ////}
  39. SimpleIoc.Default.Register<MainViewModel>();
  40. }
  41. public MainViewModel Main
  42. {
  43. get
  44. {
  45. return ServiceLocator.Current.GetInstance<MainViewModel>();
  46. }
  47. }
  48. public static void Cleanup()
  49. {
  50. // TODO Clear the ViewModels
  51. }
  52. }
  53. }