Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit aededd6

Browse files
author
gumme
committed
Moving controls several steps by holding down arrow keys is now working again.
Removed canvas special handling in DesignPanel and instead letting each placement behavior handle its own special needs, and handling the Canvas issue by overriding GetPosition in CanvasPlacementSupport instead. Fixed SetPosition in CanvasPlacementSupport so Left/Top properties have priority over Right/Bottom, as this is the priority that the runtime uses.
1 parent 8fa0692 commit aededd6

2 files changed

Lines changed: 60 additions & 29 deletions

File tree

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,28 +377,35 @@ void DesignPanel_KeyDown(object sender, KeyEventArgs e)
377377
placementOp = PlacementOperation.Start(Context.Services.Selection.SelectedItems, PlacementType.Move);
378378
}
379379

380+
switch (e.Key) {
381+
case Key.Left:
382+
dx += Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1;
383+
break;
384+
case Key.Up:
385+
dy += Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1;
386+
break;
387+
case Key.Right:
388+
dx += Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1;
389+
break;
390+
case Key.Down:
391+
dy += Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1;
392+
break;
393+
}
380394

381-
dx = (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0;
382-
dy = (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0;
383-
dx = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : (dx != 0 ? dx : 0);
384-
dy = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : (dy != 0 ? dy : 0);
385-
double left, top;
386395
foreach (PlacementInformation info in placementOp.PlacedItems)
387396
{
388-
//Let canvas position preceed bounds definition since there can be a discrepancy between them.
389-
left = IsPropertySet(info.Item.View,Canvas.LeftProperty)?(double)info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance: info.OriginalBounds.Left;
390-
391-
top = IsPropertySet(info.Item.View, Canvas.TopProperty) ? (double)info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance : info.OriginalBounds.Top;
397+
var bounds = info.OriginalBounds;
398+
392399
if (!Keyboard.IsKeyDown(Key.LeftCtrl)) {
393-
info.Bounds = new Rect(left + dx,
394-
top + dy,
395-
info.OriginalBounds.Width,
396-
info.OriginalBounds.Height);
400+
info.Bounds = new Rect(bounds.Left + dx,
401+
bounds.Top + dy,
402+
bounds.Width,
403+
bounds.Height);
397404
} else {
398-
info.Bounds = new Rect(left,
399-
top,
400-
info.OriginalBounds.Width + dx,
401-
info.OriginalBounds.Height + dy);
405+
info.Bounds = new Rect(bounds.Left,
406+
bounds.Top,
407+
bounds.Width + dx,
408+
bounds.Height + dy);
402409
}
403410
placementOp.CurrentContainerBehavior.SetPosition(info);
404411
}

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@ protected override void OnInitialized()
5858
extendedView = (FrameworkElement)this.ExtendedItem.View;
5959
}
6060

61+
public override Rect GetPosition(PlacementOperation operation, DesignItem item)
62+
{
63+
UIElement child = item.View;
64+
65+
if (child == null)
66+
return Rect.Empty;
67+
68+
double x, y;
69+
70+
if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) {
71+
x = GetCanvasProperty(child, Canvas.LeftProperty);
72+
} else {
73+
x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) - child.RenderSize.Width;
74+
}
75+
76+
77+
if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) {
78+
y = GetCanvasProperty(child, Canvas.TopProperty);
79+
} else {
80+
y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) - child.RenderSize.Height;
81+
}
82+
83+
var p = new Point(x, y);
84+
return new Rect(p, child.RenderSize);
85+
}
86+
6187
public override void SetPosition(PlacementInformation info)
6288
{
6389
base.SetPosition(info);
@@ -66,28 +92,26 @@ public override void SetPosition(PlacementInformation info)
6692
UIElement child = info.Item.View;
6793
Rect newPosition = info.Bounds;
6894

69-
if (IsPropertySet(child, Canvas.RightProperty))
70-
{
95+
if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) {
96+
if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty)) {
97+
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
98+
}
99+
} else {
71100
var newR = extendedComponent.ActualWidth - newPosition.Right;
72101
if (newR != GetCanvasProperty(child, Canvas.RightProperty))
73102
info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR);
74103
}
75-
else if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty))
76-
{
77-
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
78-
}
79104

80105

81-
if (IsPropertySet(child, Canvas.BottomProperty))
82-
{
106+
if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) {
107+
if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty)) {
108+
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
109+
}
110+
} else {
83111
var newB = extendedComponent.ActualHeight - newPosition.Bottom;
84112
if (newB != GetCanvasProperty(child, Canvas.BottomProperty))
85113
info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB);
86114
}
87-
else if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty))
88-
{
89-
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
90-
}
91115

92116
if (info.Item == Services.Selection.PrimarySelection)
93117
{

0 commit comments

Comments
 (0)