Reputation: 1618
We are using Adorners to drag/drop, rotate and resize object on canvas. That works fine but when all the object are selected on canvas or a subset of it and we try to rotate them or resize them each object runs to a different direction. can experts give us some clue where to look at and what can be done?
it will be appreciated greatly.
Thanks.
Upvotes: 0
Views: 1472
Reputation: 21
I was having the similar issue. Here is the code that I implemented:
private void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
var designerItem = this.DataContext as DesignerItem;
var designer = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas;
if (designerItem != null && designer != null && designerItem.IsSelected)
{
var minLeft = double.MaxValue;
var minTop = double.MaxValue;
//We only move DesignerItems
var designerItems = designer.SelectionService.CurrentSelection.OfType<DesignerItem>();
foreach (var item in designerItems)
{
var left = Canvas.GetLeft(item);
var top = Canvas.GetTop(item);
minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
minTop = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
}
var deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
var deltaVertical = Math.Max(-minTop, e.VerticalChange);
foreach (var item in designerItems)
{
var rotateTransform = designerItem.RenderTransform as RotateTransform;
var left = Canvas.GetLeft(item);
var top = Canvas.GetTop(item);
if (double.IsNaN(left))
left = 0;
if (double.IsNaN(top))
top = 0;
if (rotateTransform != null)
{
var dragDelta = new Point(e.HorizontalChange, e.VerticalChange);
dragDelta = rotateTransform.Transform(dragDelta);
Canvas.SetLeft(item, left + dragDelta.X);
Canvas.SetTop(item, top+ dragDelta.Y);
}
else
{
Canvas.SetLeft(item, left + deltaHorizontal);
Canvas.SetTop(item, top + deltaVertical);
}
}
designer.InvalidateMeasure();
e.Handled = true;
}
}
Let me know if you that resolves the issue.
Upvotes: 2
Reputation: 10743
You may be looking for the bounding box solution proposed here: http://social.msdn.microsoft.com/Forums/en/wpf/thread/54659b47-554c-47da-8158-c944687e7339
Adorn whatever surface your selected objects are on since that is the scope of your selection. Position and size the adorner manually, instead of using the Adorner's default behaviour.
Upvotes: 1