use layout transform on root element

This commit is contained in:
jkuehner 2018-11-04 13:14:19 +01:00
Родитель 6a808c6fd1
Коммит 90160c8060
2 изменённых файлов: 13 добавлений и 12 удалений

Просмотреть файл

@ -66,8 +66,8 @@ namespace ICSharpCode.WpfDesign.Designer
this.AddCommandHandler(Commands.AlignCenterCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.AlignRightCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.Right), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.RotateLeftCommand, () => ModelTools.ApplyTransform(this.DesignContext.Services.Selection.PrimarySelection, new RotateTransform(-90)), () => this.DesignContext.Services.Selection.PrimarySelection != null);
this.AddCommandHandler(Commands.RotateRightCommand, () => ModelTools.ApplyTransform(this.DesignContext.Services.Selection.PrimarySelection, new RotateTransform(90)), () => this.DesignContext.Services.Selection.PrimarySelection != null);
this.AddCommandHandler(Commands.RotateLeftCommand, () => ModelTools.ApplyTransform(this.DesignContext.Services.Selection.PrimarySelection, new RotateTransform(-90), true, this.DesignContext.RootItem == this.DesignContext.Services.Selection.PrimarySelection ? LayoutTransformProperty : RenderTransformProperty), () => this.DesignContext.Services.Selection.PrimarySelection != null);
this.AddCommandHandler(Commands.RotateRightCommand, () => ModelTools.ApplyTransform(this.DesignContext.Services.Selection.PrimarySelection, new RotateTransform(90), true, this.DesignContext.RootItem == this.DesignContext.Services.Selection.PrimarySelection ? LayoutTransformProperty : RenderTransformProperty), () => this.DesignContext.Services.Selection.PrimarySelection != null);
this.AddCommandHandler(Commands.StretchToSameWidthCommand, () => ModelTools.StretchItems(this.DesignContext.Services.Selection.SelectedItems, StretchDirection.Width), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.StretchToSameHeightCommand, () => ModelTools.StretchItems(this.DesignContext.Services.Selection.SelectedItems, StretchDirection.Height), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);

Просмотреть файл

@ -501,13 +501,14 @@ namespace ICSharpCode.WpfDesign.Designer
operation.Commit();
}
public static void ApplyTransform(DesignItem designItem, Transform transform, bool relative = true)
public static void ApplyTransform(DesignItem designItem, Transform transform, bool relative = true, DependencyProperty transformProperty = null)
{
var changeGroup = designItem.OpenGroup("Apply Transform");
transformProperty = transformProperty ?? FrameworkElement.RenderTransformProperty;
Transform oldTransform = null;
if (designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).IsSet) {
oldTransform = designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).ValueOnInstance as Transform;
if (designItem.Properties.GetProperty(transformProperty).IsSet) {
oldTransform = designItem.Properties.GetProperty(transformProperty).ValueOnInstance as Transform;
}
if (oldTransform is MatrixTransform) {
@ -538,22 +539,22 @@ namespace ICSharpCode.WpfDesign.Designer
if (oldTransform is RotateTransform || oldTransform == null) {
if (rotateTransform.Angle != 0) {
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(transform);
designItem.Properties.GetProperty(transformProperty).SetValue(transform);
var angle = rotateTransform.Angle;
if (relative && oldTransform != null) {
angle = rotateTransform.Angle + ((RotateTransform)oldTransform).Angle;
}
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.AngleProperty).SetValue(angle);
designItem.Properties.GetProperty(transformProperty).Value.Properties.GetProperty(RotateTransform.AngleProperty).SetValue(angle);
if (rotateTransform.CenterX != 0.0)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterXProperty).SetValue(rotateTransform.CenterX);
designItem.Properties.GetProperty(transformProperty).Value.Properties.GetProperty(RotateTransform.CenterXProperty).SetValue(rotateTransform.CenterX);
if (rotateTransform.CenterY != 0.0)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterYProperty).SetValue(rotateTransform.CenterY);
designItem.Properties.GetProperty(transformProperty).Value.Properties.GetProperty(RotateTransform.CenterYProperty).SetValue(rotateTransform.CenterY);
if (oldTransform == null)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
}
else {
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Reset();
designItem.Properties.GetProperty(transformProperty).Reset();
designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).Reset();
}
} else if (oldTransform is TransformGroup) {
@ -572,7 +573,7 @@ namespace ICSharpCode.WpfDesign.Designer
}
} else {
if (rotateTransform.Angle != 0) {
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(transform);
designItem.Properties.GetProperty(transformProperty).SetValue(transform);
if (oldTransform == null)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
}