From c47075cc333329fc6bc93679d847cadcb050436f Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 4 Dec 2017 13:41:01 +0200 Subject: Added MVVMLight nuget. Implemented ViewModel IView, supervising controller pattern. --- .../Tango.MachineDesigner.UI/ViewModelLocator.cs | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs (limited to 'Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs') 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: + + + + + 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 +{ + /// + /// This class contains static references to all the view models in the + /// application and provides an entry point for the bindings. + /// + public class ViewModelLocator + { + /// + /// Initializes a new instance of the ViewModelLocator class. + /// + public ViewModelLocator() + { + ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); + + ////if (ViewModelBase.IsInDesignModeStatic) + ////{ + //// // Create design time view services and models + //// SimpleIoc.Default.Register(); + ////} + ////else + ////{ + //// // Create run time view services and models + //// SimpleIoc.Default.Register(); + ////} + + SimpleIoc.Default.Register(); + + //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(); + } + } + + public static void Cleanup() + { + // TODO Clear the ViewModels + } + } +} \ No newline at end of file -- cgit v1.3.1