From 7e238a9b5289501b8a8ecf470242a626c0647c17 Mon Sep 17 00:00:00 2001 From: tbulle Date: Wed, 14 May 2014 16:59:30 +0200 Subject: [PATCH] Fix for skewed checkbox movement on arrow key press --- .../WpfDesign.Designer/Project/DesignPanel.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index 0a5ba978a3..f5cf884dae 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -368,8 +368,7 @@ namespace ICSharpCode.WpfDesign.Designer void DesignPanel_KeyDown(object sender, KeyEventArgs e) { - if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down) - { + if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down) { e.Handled = true; if (placementOp == null) { @@ -379,32 +378,38 @@ namespace ICSharpCode.WpfDesign.Designer } - dx += (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0; - dy += (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0; - dx += (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : 0; - dy += (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : 0; + dx = (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0; + dy = (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0; + dx = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : 0; + dy = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : 0; + double left, top; foreach (PlacementInformation info in placementOp.PlacedItems) { - if (!Keyboard.IsKeyDown(Key.LeftCtrl)) - { - info.Bounds = new Rect(info.OriginalBounds.Left + dx, - info.OriginalBounds.Top + dy, + //Let canvas position preceed bounds definition since there can be a discrepancy between them. + left = IsPropertySet(info.Item.View,Canvas.LeftProperty)?(double)info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance: info.OriginalBounds.Left; + + top = IsPropertySet(info.Item.View, Canvas.TopProperty) ? (double)info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance : info.OriginalBounds.Top; + if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { + info.Bounds = new Rect(left + dx, + top + dy, info.OriginalBounds.Width, info.OriginalBounds.Height); - } - else - { - info.Bounds = new Rect(info.OriginalBounds.Left, - info.OriginalBounds.Top, + } else { + info.Bounds = new Rect(left, + top, info.OriginalBounds.Width + dx, info.OriginalBounds.Height + dy); } - placementOp.CurrentContainerBehavior.SetPosition(info); } } } + static bool IsPropertySet(UIElement element, DependencyProperty d) + { + return element.ReadLocalValue(d) != DependencyProperty.UnsetValue; + } + protected override void OnQueryCursor(QueryCursorEventArgs e) { base.OnQueryCursor(e);