我们正在使用 Adorners 在画布上拖放、旋转和调整对象大小。这很好用,但是当在画布上选择所有对象或其子集时,我们尝试旋转它们或调整它们的大小,每个对象都会向不同的方向运行。专家能否给我们一些线索,从哪里看,可以做什么?
将不胜感激。
谢谢。
我遇到了类似的问题。这是我实现的代码:
void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
DesignerItem designerItem = this.DataContext as DesignerItem;
DesignerCanvas designer = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas;
if (designerItem != null && designer != null && designerItem.IsSelected)
{
double minLeft = double.MaxValue;
double minTop = double.MaxValue;
// we only move DesignerItems
var designerItems = designer.SelectionService.CurrentSelection.OfType<DesignerItem>();
foreach (DesignerItem item in designerItems)
{
double left = Canvas.GetLeft(item);
double top = Canvas.GetTop(item);
minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
minTop = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
}
double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
double deltaVertical = Math.Max(-minTop, e.VerticalChange);
foreach (DesignerItem item in designerItems)
{
RotateTransform rotateTransform = designerItem.RenderTransform as RotateTransform;
double left = Canvas.GetLeft(item);
double top = Canvas.GetTop(item);
if (double.IsNaN(left)) left = 0;
if (double.IsNaN(top)) top = 0;
if (rotateTransform != null)
{
Point 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;
}
}
让我知道您是否可以解决问题。
您可能正在寻找这里提出的边界框解决方案:http: //social.msdn.microsoft.com/Forums/en/wpf/thread/54659b47-554c-47da-8158-c944687e7339
装饰您选择的对象所在的任何表面,因为那是您选择的范围。手动定位和调整装饰器的大小,而不是使用装饰器的默认行为。