aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2017-12-04 13:41:01 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2017-12-04 13:41:01 +0200
commitc47075cc333329fc6bc93679d847cadcb050436f (patch)
tree7d6400a6008598925fff341d3b4ef38f3074c081 /Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs
parent326925941657d0e6968103e60ec1972fab64d4b0 (diff)
downloadTango-c47075cc333329fc6bc93679d847cadcb050436f.tar.gz
Tango-c47075cc333329fc6bc93679d847cadcb050436f.zip
Added MVVMLight nuget.
Implemented ViewModel IView, supervising controller pattern.
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs
new file mode 100644
index 000000000..db490a8e3
--- /dev/null
+++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs
@@ -0,0 +1,73 @@
+/*
+ In App.xaml:
+ <Application.Resources>
+ <vm:ViewModelLocator xmlns:vm="clr-namespace:Tango.MachineDesigner.UI"
+ x:Key="Locator" />
+ </Application.Resources>
+
+ In the View:
+ DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
+
+ You can also use Blend to do all this with the tool's support.
+ See http://www.galasoft.ch/mvvm
+*/
+
+using GalaSoft.MvvmLight;
+using GalaSoft.MvvmLight.Ioc;
+using Microsoft.Practices.ServiceLocation;
+using System;
+using Tango.Logging;
+using Tango.MachineDesigner.UI.SupervisingController;
+using Tango.MachineDesigner.UI.ViewModels;
+using Tango.MachineDesigner.UI.Views;
+
+namespace Tango.MachineDesigner.UI
+{
+ /// <summary>
+ /// This class contains static references to all the view models in the
+ /// application and provides an entry point for the bindings.
+ /// </summary>
+ public class ViewModelLocator
+ {
+ /// <summary>
+ /// Initializes a new instance of the ViewModelLocator class.
+ /// </summary>
+ public ViewModelLocator()
+ {
+ ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
+
+ ////if (ViewModelBase.IsInDesignModeStatic)
+ ////{
+ //// // Create design time view services and models
+ //// SimpleIoc.Default.Register<IDataService, DesignDataService>();
+ ////}
+ ////else
+ ////{
+ //// // Create run time view services and models
+ //// SimpleIoc.Default.Register<IDataService, DataService>();
+ ////}
+
+ SimpleIoc.Default.Register<MainViewVM>();
+
+ //Register View (Supervising Controller Pattern).
+ if (!ViewModelBase.IsInDesignModeStatic)
+ {
+ LogManager.Log(String.Format("Registering Supervising Controller {0}...",nameof(IMainView)));
+ SimpleIoc.Default.Register(() => (IMainView)MainView.Self);
+ }
+ }
+
+ public MainViewVM MainViewVM
+ {
+ get
+ {
+ return ServiceLocator.Current.GetInstance<MainViewVM>();
+ }
+ }
+
+ public static void Cleanup()
+ {
+ // TODO Clear the ViewModels
+ }
+ }
+} \ No newline at end of file