Browse Source

Merge pull request #501 from gumme/WpfDesignerCanvasPlacementFix

Wpf designer placement fixes
pull/503/head
Andreas Weizel 11 years ago
parent
commit
2d27f61032
  1. 41
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  2. 48
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

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

@ -377,28 +377,35 @@ namespace ICSharpCode.WpfDesign.Designer @@ -377,28 +377,35 @@ namespace ICSharpCode.WpfDesign.Designer
placementOp = PlacementOperation.Start(Context.Services.Selection.SelectedItems, PlacementType.Move);
}
switch (e.Key) {
case Key.Left:
dx += Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1;
break;
case Key.Up:
dy += Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1;
break;
case Key.Right:
dx += Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1;
break;
case Key.Down:
dy += Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1;
break;
}
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 : (dx != 0 ? dx : 0);
dy = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : (dy != 0 ? dy : 0);
double left, top;
foreach (PlacementInformation info in placementOp.PlacedItems)
{
//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;
var bounds = info.OriginalBounds;
if (!Keyboard.IsKeyDown(Key.LeftCtrl)) {
info.Bounds = new Rect(left + dx,
top + dy,
info.OriginalBounds.Width,
info.OriginalBounds.Height);
info.Bounds = new Rect(bounds.Left + dx,
bounds.Top + dy,
bounds.Width,
bounds.Height);
} else {
info.Bounds = new Rect(left,
top,
info.OriginalBounds.Width + dx,
info.OriginalBounds.Height + dy);
info.Bounds = new Rect(bounds.Left,
bounds.Top,
bounds.Width + dx,
bounds.Height + dy);
}
placementOp.CurrentContainerBehavior.SetPosition(info);
}

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

@ -58,6 +58,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -58,6 +58,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
extendedView = (FrameworkElement)this.ExtendedItem.View;
}
public override Rect GetPosition(PlacementOperation operation, DesignItem item)
{
UIElement child = item.View;
if (child == null)
return Rect.Empty;
double x, y;
if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) {
x = GetCanvasProperty(child, Canvas.LeftProperty);
} else {
x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) - child.RenderSize.Width;
}
if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) {
y = GetCanvasProperty(child, Canvas.TopProperty);
} else {
y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) - child.RenderSize.Height;
}
var p = new Point(x, y);
return new Rect(p, child.RenderSize);
}
public override void SetPosition(PlacementInformation info)
{
base.SetPosition(info);
@ -66,28 +92,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -66,28 +92,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
UIElement child = info.Item.View;
Rect newPosition = info.Bounds;
if (IsPropertySet(child, Canvas.RightProperty))
{
if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) {
if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty)) {
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
}
} else {
var newR = extendedComponent.ActualWidth - newPosition.Right;
if (newR != GetCanvasProperty(child, Canvas.RightProperty))
info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR);
}
else if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty))
{
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
}
if (IsPropertySet(child, Canvas.BottomProperty))
{
if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) {
if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty)) {
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
}
} else {
var newB = extendedComponent.ActualHeight - newPosition.Bottom;
if (newB != GetCanvasProperty(child, Canvas.BottomProperty))
info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB);
}
else if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty))
{
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
}
if (info.Item == Services.Selection.PrimarySelection)
{

Loading…
Cancel
Save