private void OnLoadUserLayout(LoadUserLayoutModel obj)
 {
     if (obj.IsFlagMode)
         LoadLayoutForFlagMode(obj.UserSettings);
     else
         LoadLayoutForEdit(obj.UserSettings);
 }
 void context_LoadUserLayoutEvent(LoadUserLayoutModel loadUserLayoutModel)
 {
     if (LoadUserLayoutCommand != null && LoadUserLayoutCommand.CanExecute(loadUserLayoutModel))
         LoadUserLayoutCommand.Execute(loadUserLayoutModel);
 }
        public void InitializePlateControl(LayoutEditorPopulation layoutEditorPopulation)
        {
            if (layoutEditorPopulation == null)
                return;
            if (Equals(_userSettings, null))
                throw new InvalidOperationException("Please bind the UserSettings firstly");

            _layoutEditorPopulation = layoutEditorPopulation;
            ControlSettings = new ControlSettingsModel();

            _plateControl.PosMouseCursor = Cursors.Arrow;
            _plateControl.SkipCheckForFontSizeRecalc = true;

            _plateControl.LocationMouseButtonUp += new PlateControl2DSilverlight.MouseEvents.LocationMouseButtonUpEventHandler(plateControl_LocationMouseButtonUp);
            _plateControl.LocationMouseButtonDown += new PlateControl2DSilverlight.MouseEvents.LocationMouseButtonDownEventHandler(plateControl_LocationMouseButtonDown);
            _plateControl.LocationMouseOver += new PlateControl2DSilverlight.MouseEvents.LocationMouseOverEventHandler(plateControl2D_LocationMouseOver);

            FillSettings = new FillSettingsModel(_userSettings) { GroupNum = 1, SelectedSampleTypeIndex = -1 };
            FillSettings.PropertyChanged += _fillSettings_PropertyChanged;

            FillSettings.SampleTypes = _layoutEditorPopulation.SampleTypes;
            FillSettings.SelectedSampleTypeIndex = FillSettings.SampleTypes.Count - 1;

            _editorStateHelper = new EditorStateHelper(_layoutEditorPopulation, _userSettings) { };
            _editorStateHelper.PropertyChanged += _editorStateHelper_PropertyChanged;

            // When using RackMode, force fill mode to be across (down doesn't make much sense in rack mode)
            if (_layoutEditorPopulation.RackMode)
            {
                FillSettings.FillDirection = Direction.Across;
                FillSettings.ShowNextTime = true;
            }
            // Fill mode is allowed if we are NOT in EraseOnly and we are NOT in flag mode
            ControlSettings.AllowFillMode = !_layoutEditorPopulation.EraseOnly && !_userSettings.IsFlagMode;
            ControlSettings.IsFlagMode = _userSettings.IsFlagMode;
            // Clear button is available unless in Erase only mode (although it is only enabled when there is something to clear).
            ControlSettings.AllowClearButton = !_layoutEditorPopulation.EraseOnly;
            // If Fill mode is not allowed then set SelectedSampleTypeIndex to -1 so ListBox has no items selected (i.e. it looks just like a legend display)
            if (!ControlSettings.AllowFillMode)
                FillSettings.SelectedSampleTypeIndex = -1;
            ControlSettings.SelectionCommand = ControlSettings.IsFlagMode ? SelectionCommand.Flag : SelectionCommand.Erase;

            if (LoadUserLayoutEvent != null)
            {
                var loadUserLayoutmodel = new LoadUserLayoutModel();
                loadUserLayoutmodel.UserSettings = _userSettings;
                loadUserLayoutmodel.IsFlagMode = ControlSettings.IsFlagMode;
                LoadUserLayoutEvent(loadUserLayoutmodel);
            }
            OnUpdateControlSettings();
        }