/// <summary/> public TopLeftContainerDragHandle() { ContainerDragHandle rect = new ContainerDragHandle(); rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto); new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e); e.Handled=true; }; RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top); p.XOffset = -7; p.YOffset = -7; AddAdorner(p, AdornerOrder.Background, rect); }
protected override void OnInitialized() { base.OnInitialized(); ContainerDragHandle rect = new ContainerDragHandle(); rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { //Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto); new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e); e.Handled=true; }; var items = this.ExtendedItem.Services.Selection.SelectedItems; double minX = 0; double minY = 0; double maxX = 0; double maxY = 0; foreach (DesignItem di in items) { Point relativeLocation = di.View.TranslatePoint(new Point(0, 0), this.ExtendedItem.View); minX = minX < relativeLocation.X ? minX : relativeLocation.X; minY = minY < relativeLocation.Y ? minY : relativeLocation.Y; maxX = maxX > relativeLocation.X + ((FrameworkElement)di.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)di.View).ActualWidth; maxY = maxY > relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight; } Rectangle rect2 = new Rectangle() { Width = (maxX - minX) + 4, Height = (maxY - minY) + 4, Stroke = Brushes.Black, StrokeThickness = 2, StrokeDashArray = new DoubleCollection(){ 2, 2 }, }; RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top); p.XOffset = minX - 3; p.YOffset = minY - 3; RelativePlacement p2 = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top); p2.XOffset = (minX + rect2.Width) - 2; p2.YOffset = (minY + rect2.Height) - 2; AddAdorner(p, AdornerOrder.Background, rect); AddAdorner(p2, AdornerOrder.Background, rect2); }