From 90160c806004f0d74fb2cf9bba07be6576f7c8f2 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Sun, 4 Nov 2018 13:14:19 +0100 Subject: [PATCH] use layout transform on root element --- WpfDesign.Designer/Project/DesignSurface.cs | 4 ++-- WpfDesign.Designer/Project/ModelTools.cs | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/WpfDesign.Designer/Project/DesignSurface.cs b/WpfDesign.Designer/Project/DesignSurface.cs index 04d20be..6ff387c 100644 --- a/WpfDesign.Designer/Project/DesignSurface.cs +++ b/WpfDesign.Designer/Project/DesignSurface.cs @@ -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); diff --git a/WpfDesign.Designer/Project/ModelTools.cs b/WpfDesign.Designer/Project/ModelTools.cs index 838554b..8fa5327 100644 --- a/WpfDesign.Designer/Project/ModelTools.cs +++ b/WpfDesign.Designer/Project/ModelTools.cs @@ -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)); }