void context_UpdateControlSettingsEvent(ControlSettingsModel controlSettings)
        {
           
            _controlSettings = controlSettings;
          
                plateControlhidden.PointData = plateControl.PointData;
            
           
         
            #region Update thumbnail
            if (leftMenu != null)
            {
                if (leftMenu.Items.Count > 0)
                {
                    leftMenu.SelectedIndex = 0;
                    if (leftMenu.SelectedItem != null)
                    {
                        var image = new System.Windows.Media.Imaging.BitmapImage();
                        image.SetSource(plateControl.SaveAsImage());
                        ((LeftMenuModel)leftMenu.SelectedItem).Image = image;

                        leftMenu.ItemsSource = null;
                        leftMenu.ItemsSource = LeftMenuContent;
                    }

                }

            }
            #endregion


            btnSaveClose.IsEnabled = controlSettings.IsSaveAvailable;
            btnUndo.IsEnabled = controlSettings.IsUndoAvailable;
            btnRedo.IsEnabled = controlSettings.IsRedoAvailable;

            btnClear.IsEnabled = controlSettings.IsClearAvailable;
            btnClear.Visibility = controlSettings.IsClearAvailable ? Visibility.Visible : Visibility.Collapsed;

            btnErase.Visibility = controlSettings.AllowFillMode ? Visibility.Visible : Visibility.Collapsed;
            btnFill.Visibility = controlSettings.AllowFillMode ? Visibility.Visible : Visibility.Collapsed;
            btnFillSettings.Visibility = controlSettings.SelectionCommand == Models.SelectionCommand.Fill ?
                Visibility.Visible : Visibility.Collapsed;

            spGroupNumEditor.Visibility = controlSettings.AllowFillMode ?
                Visibility.Visible : Visibility.Collapsed;
            lbSampleTypes.IsEnabled = controlSettings.AllowFillMode;

            SelectionCommand = controlSettings.SelectionCommand;
            if (CurrentStateChangeCommand != null && CurrentStateChangeCommand.CanExecute(controlSettings.CurrentState))
                CurrentStateChangeCommand.Execute(controlSettings.CurrentState);
        }
        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();
        }