public ModulesVM(ConnectionVM connection, SettingsVM settings, ModuleVM menu, params ModuleVM[] modules)
        {
            //set fields
            _connection              = connection;
            _settings                = settings;
            _menu                    = menu;
            Modules                  = new ObservableCollection <ModuleVM>(modules);
            ModuleColumns            = new ObservableCollection <ObservableCollection <ModuleVM> >();
            ModuleSizeChangedCommand = new RelayCommand <SizeChangedEventArgs>(ModuleSizeChanged);

            //connect to events
            _connectionEvents = new PropertyObserver <ConnectionVM>(_connection)
                                .RegisterHandler(i => i.CurrentArm, CurrentRobotChanged)
                                .RegisterHandler(i => i.Ports, PortsChanged)
                                .RegisterHandler(i => i.IsScanning, ScanningChanged);
            _settingsEvents = new PropertyObserver <SettingsVM>(_settings)
                              .RegisterHandler(i => i.FirstTimeUse, FirstTimeUseChanged);
            settings.HasReset += Settings_HasReset;
            foreach (var module in modules)
            {
                module.Selected += Module_Selected;
            }
            App.Current.Exit += Current_Exit;

            UpdateRobotChanged();
            GotoMenu();
        }
        void LoadControl(ModuleVM module)
        {
            //construct control
            if (module.Control == null)
            {
                module.Control = Activator.CreateInstance(module.ControlType) as UserControl;
                //attach the view model
                if (module.ViewModelType != null)
                {
                    module.Control.DataContext = Activator.CreateInstance(module.ViewModelType);
                }
            }

            //set transition
            SelectedModuleTransition = module.Transition;

            //call module methods
            if (module.Control != null)
            {
                var mod = module.Control as IModule;
                mod?.ShowingModule();
                mod = module.Control.DataContext as IModule;
                mod?.ShowingModule();
                if (mod == null && module == _menu)
                {
                    mod = this as IModule;
                    mod?.ShowingModule();
                }
            }
        }
        void UnloadControl(ModuleVM module)
        {
            if (module == null)
            {
                return;
            }

            //call module methods
            if (module.Control != null)
            {
                var mod = module.Control as IModule;
                mod?.HidingModule();
                mod = module.Control.DataContext as IModule;
                mod?.HidingModule();
                if (mod == null && module == _menu)
                {
                    mod = this as IModule;
                    mod?.HidingModule();
                }
            }
        }
 void Module_Selected(ModuleVM module)
 {
     SelectedModule = module;
 }