解决Lock之后 unlock 不了的问题
1.DesignPanel.cs
protectedvoidDesignPanelPreviewMouseLeftButtonDown(objectsender, MouseButtonEventArgse)
#region No Key
if (!_selectedElementDict.ContainsKey(currentElement))
{
foreach (FrameworkElementelementin_selectedElementDict.Keys)
{
if (elementisCommonElement) { ((CommonElement)element).ShowBorder=false; }
}
_selectedElementDict.Clear();
//if (currentElement != null && GetAllowDesign(currentElement))
if (currentElement!=null)
{
_selectedElementDict.Add(currentElement, newRect());
if (currentElementisCommonElement) ((CommonElement)currentElement).ShowBorder=true;
FocusedElement=currentElement;
}
OnSelectionChanged(newEventArgs());
}
2.DesignPanel.cs
protectedvoidDesignPanelPreviewMouseMove(objectsender, MouseEventArgse)
if (_direction==Direction.None)
{
foreach (FrameworkElementelementin_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))
{
Rectrect=_selectedElementDict[element];
doubleleft=rect.X;
doubletop=rect.Y;
element.Margin=newThickness(left+position.X-_position.X,
top+position.Y-_position.Y, element.Margin.Right, element.Margin.Bottom);
}
}
if (_selectedElementDict.Count>0)
{
OnElementPositionChanged(newEventArgs());
}
}
3. CommonElement.cs
publicvirtualvoidSelected(SCTemplateViewview)
{
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
publicoverridevoidSelected(SCTemplateViewview)
{
// 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 (inti=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 (intj=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 (inti=0; i<ElementDecorations.lsFontWeight.Count; i++)
{
if (FontWeight+""==ElementDecorations.lsFontWeight[i].ToString())
{
view.cbFontWeight.SelectedIndex=i;
break;
}
}
#endregion
#region FontStyle
for (inti=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 (inti=0; i<ElementDecorations.lsTextDecoration.Count; i++)
{
TextBlocktBlock=this.textBlock;
if (tBlock!=null)
{
intnum=tBlock.TextDecorations.Count;
TextDecorationtDecoration=tBlock.TextDecorations[0];
stringstrD=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>
privatevoidcbIsLocked_Click(objectsender, RoutedEventArgse)
{
CheckBoxcbox=senderasCheckBox;
if (cbox!=null)
{
boolbCanDesign= (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;
}
}