解决Lock之后 unlock 不了的问题

解决Lock之后 unlock 不了的问题

 

1. DesignPanel.cs

 

protected void DesignPanelPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)

 

#region No Key

 

if (!_selectedElementDict.ContainsKey(currentElement))

                    {

                        foreach (FrameworkElement element in _selectedElementDict.Keys)

                        {

                            if (element is CommonElement) { ((CommonElement)element).ShowBorder = false; }

                        }

 

                        _selectedElementDict.Clear();

                        //if (currentElement != null && GetAllowDesign(currentElement))

                        if (currentElement != null)

                        {

                            _selectedElementDict.Add(currentElement, new Rect());

                            if (currentElement is CommonElement) ((CommonElement)currentElement).ShowBorder = true;

 

                            FocusedElement = currentElement;

                        }

 

                        OnSelectionChanged(new EventArgs());

                    }

 

2.DesignPanel.cs

protected void DesignPanelPreviewMouseMove(object sender, MouseEventArgs e)

if (_direction == Direction.None)

                {

                    foreach (FrameworkElement element in _selectedElementDict.Keys)

                    {

                        //Rect rect = _selectedElementDict[element];

                        //double left = rect.X;

                        //double top = rect.Y;

                        //element.Margin = new Thickness(left + position.X - _position.X,

                        //    top + position.Y - _position.Y, element.Margin.Right, element.Margin.Bottom);

 

                        if (GetAllowDesign(element))

                        {

                            Rect rect = _selectedElementDict[element];

                            double left = rect.X;

                            double top = rect.Y;

                            element.Margin = new Thickness(left + position.X - _position.X,

                                top + position.Y - _position.Y, element.Margin.Right, element.Margin.Bottom);

                        }

                    }

 

                    if (_selectedElementDict.Count > 0)

                    {

                        OnElementPositionChanged(new EventArgs());

                    }

                }

3. CommonElement.cs

public virtual void Selected(SCTemplateView view)

        {

           

            view.cbTextDecorations.SelectedIndex = -1;

            view.cbTextDecorations.IsEnabled = false;

            view.cbxFontColor.SelectedIndex = -1;

            view.cbxFontColor.IsEnabled = false;

            view.cbxColor.SelectedIndex = -1;

            view.cbxColor.IsEnabled = false;

            view.cbFontSize.SelectedIndex = -1;

            view.cbFontSize.IsEnabled = false;

            view.cbFontStyle.SelectedIndex = -1;

            view.cbFontStyle.IsEnabled = false;

            view.cbFontWeight.SelectedIndex = -1;

            view.cbFontWeight.IsEnabled = false;

 

 

            view.txtName.IsReadOnly = !this.CanDesign;

            view.cbVisible.IsEnabled = !this.CanDesign;

            view.txtLeft.IsReadOnly = !this.CanDesign;

            view.txtTop.IsReadOnly = !this.CanDesign;

            view.txtWidth.IsReadOnly = !this.CanDesign;

            view.txtHeight.IsReadOnly = !this.CanDesign;

            view.txtZIndex.IsReadOnly = !this.CanDesign;

            view.cbxColor.IsReadOnly = !this.CanDesign;

            view.cbFontSize.IsReadOnly = !this.CanDesign;

            view.cbxFontColor.IsReadOnly = !this.CanDesign;

            view.cbFontWeight.IsReadOnly = !this.CanDesign;

            view.cbFontStyle.IsReadOnly = !this.CanDesign;

            view.cbTextDecorations.IsReadOnly = !this.CanDesign;

            //view.cbIsLocked.IsEnabled = this.CanDesign;

        }

4. TextBlockElement.cs

  public override void Selected(SCTemplateView view)

        {

           // base.Selected(view);

           

            view.txtName.Text = Text == null ? "" : Text;

            view.txtLeft.Text = Margin.Left + "";

            view.txtTop.Text = Margin.Top + "";

            view.txtWidth.Text = Width + "";

            view.txtHeight.Text = Height + "";

 

 

            view.cbTextDecorations.IsEnabled = true;

            view.cbFontWeight.IsEnabled = true;

            view.cbFontSize.IsEnabled = true;

            view.cbFontStyle.IsEnabled = true;

            view.cbxColor.IsEnabled = true;

            view.cbxFontColor.IsEnabled = true;

 

        

            ElementDecorations.init();

 

            #region background

           

            if (Background != null)

            {

                for (int i = 0; i < ElementDecorations.lsBackGround.Count; i++)

                {

                    if (Background + "" == ElementDecorations.lsBackGround[i].ToString())

                    {

                        view.cbxColor.SelectedIndex = i;

                        break;

                    }

                }

            }

            else

            {

                view.cbxColor.SelectedIndex = 0;

            }

 

            #endregion

 

            #region Foreground

            if (Foreground + "" =="#FF000000")

            {

                view.cbxFontColor.SelectedIndex = 0;

             

            }

            else

            {

 

                for (int j = 0; j < ElementDecorations.lsFontColor.Count; j++)

                {

                    if (Foreground + "" == ElementDecorations.lsFontColor[j].ToString())

                    {

                        view.cbxFontColor.SelectedIndex = j;

                        break;

                    }

                }

            }

            #endregion

 

            #region FontSize

            if ((FontSize + "").Length > 0)

            {

                view.cbFontSize.Text = FontSize.ToString();

            }

 

            for (int i = 0; i < ElementDecorations.lsFontWeight.Count; i++)

            {

                if (FontWeight + "" == ElementDecorations.lsFontWeight[i].ToString())

                {

                    view.cbFontWeight.SelectedIndex = i;

                    break;

                }

            }

 

            #endregion

 

            #region FontStyle

 

            for (int i = 0; i < ElementDecorations.lsFontStyle.Count; i++)

            {

                if (FontStyle.ToString() == ElementDecorations.lsFontStyle[i].ToString())

                {

                    view.cbFontStyle.SelectedIndex = i;

                    break;

                }

            }

 

            #endregion

 

            #region TextDecorations  Added by xlding, 2012-03-29

            if (this.textBlock.TextDecorations.Count <= 0)

            {

                view.cbTextDecorations.SelectedIndex = -1;

            }

            else

            {

                for (int i = 0; i < ElementDecorations.lsTextDecoration.Count; i++)

                {

                    TextBlock tBlock = this.textBlock;

                    if (tBlock != null)

                    {

                        int num = tBlock.TextDecorations.Count;

                        TextDecoration tDecoration = tBlock.TextDecorations[0];

                        string strD = tBlock.TextDecorations[0].Location.ToString();

 

                        if (tBlock.TextDecorations ==

                            ElementDecorations.ConvertTextDecrationStringToTextDecorations(ElementDecorations.lsTextDecoration[i].ToString()))

                        {

 

                            view.cbTextDecorations.SelectedIndex = i;

 

                            break;

                        }

                    }

                }

            }

            #endregion

 

 

 

            view.txtName.IsReadOnly = !this.CanDesign;

            view.cbVisible.IsEnabled = !this.CanDesign;

            view.txtLeft.IsReadOnly = !this.CanDesign;

            view.txtTop.IsReadOnly = !this.CanDesign;

            view.txtWidth.IsReadOnly = !this.CanDesign;

            view.txtHeight.IsReadOnly = !this.CanDesign;

            view.txtZIndex.IsReadOnly = !this.CanDesign;

            view.cbxColor.IsReadOnly = !this.CanDesign;

            view.cbFontSize.IsReadOnly = !this.CanDesign;

            view.cbxFontColor.IsReadOnly = !this.CanDesign;

            view.cbFontWeight.IsReadOnly = !this.CanDesign;

            view.cbFontStyle.IsReadOnly = !this.CanDesign;

            view.cbTextDecorations.IsReadOnly = !this.CanDesign;

 

        }

5. SCTemplateView.cs

<CheckBox Name="cbIsLocked" Margin="2,2,0,0" Grid.Row="13" Grid.Column="1" Grid.ColumnSpan="2"

                                                  VerticalContentAlignment="Top" HorizontalContentAlignment="Left"

                                                  IsChecked="{Binding Path=CanDesign, UpdateSourceTrigger=PropertyChanged}"

                                                   Click="cbIsLocked_Click" ></CheckBox>

 

  private void cbIsLocked_Click(object sender, RoutedEventArgs e)

        {

            CheckBox cbox = sender as CheckBox;

            if (cbox != null)

            {

                bool bCanDesign = (bool)cbox.IsChecked;

                this.txtName.IsReadOnly = !bCanDesign;

                this.cbVisible.IsEnabled = !bCanDesign;

                this.txtLeft.IsReadOnly = !bCanDesign;

                this.txtTop.IsReadOnly = !bCanDesign;

                this.txtWidth.IsReadOnly = !bCanDesign;

                this.txtHeight.IsReadOnly = !bCanDesign;

                this.txtZIndex.IsReadOnly = !bCanDesign;

                this.cbxColor.IsReadOnly = !bCanDesign;

                this.cbFontSize.IsReadOnly = !bCanDesign;

                this.cbxFontColor.IsReadOnly = !bCanDesign;

                this.cbFontWeight.IsReadOnly = !bCanDesign;

                this.cbFontStyle.IsReadOnly = !bCanDesign;

                this.cbTextDecorations.IsReadOnly = !bCanDesign;

            }

        }

 

 

原文地址:https://www.cnblogs.com/quietwalk/p/2441107.html