private void ResizeableThumb_DragDelta(object sender, DragDeltaEventArgs e) { if (this._designerItem != null) { double deltaVertical, deltaHorizontal; DesignerVisualElement element = (this._designerItem.Content as ContentControl).DataContext as DesignerVisualElement; switch (VerticalAlignment) { case System.Windows.VerticalAlignment.Bottom: deltaVertical = Math.Min(-e.VerticalChange, this._designerItem.ActualHeight - this._designerItem.MinHeight); element.Position.MoveOffset(-deltaVertical * this.transformOrigin.Y * Math.Sin(-this.angle), (this.transformOrigin.Y * deltaVertical * (1 - Math.Cos(-this.angle)))); this._designerItem.Height -= deltaVertical; //element.Size.Height -= deltaVertical; break; case System.Windows.VerticalAlignment.Top: deltaVertical = Math.Min(e.VerticalChange, this._designerItem.ActualHeight - this._designerItem.MinHeight); element.Position.MoveOffset(deltaVertical * Math.Sin(-this.angle) - (this.transformOrigin.Y * deltaVertical * Math.Sin(-this.angle)), deltaVertical * Math.Cos(-this.angle) + (this.transformOrigin.Y * deltaVertical * (1 - Math.Cos(-this.angle)))); this._designerItem.Height -= deltaVertical; //element.Size.Height -= deltaVertical; break; default: break; } switch (HorizontalAlignment) { case System.Windows.HorizontalAlignment.Left: deltaHorizontal = Math.Min(e.HorizontalChange, this._designerItem.ActualWidth - this._designerItem.MinWidth); element.Position.MoveOffset(deltaHorizontal * Math.Cos(this.angle) + (this.transformOrigin.X * deltaHorizontal * (1 - Math.Cos(this.angle))), deltaHorizontal * Math.Sin(this.angle) - this.transformOrigin.X * deltaHorizontal * Math.Sin(this.angle)); this._designerItem.Width -= deltaHorizontal; //element.Size.Width -= deltaHorizontal; break; case System.Windows.HorizontalAlignment.Right: deltaHorizontal = Math.Min(-e.HorizontalChange, this._designerItem.ActualWidth - this._designerItem.MinWidth); element.Position.MoveOffset(-this.transformOrigin.X * deltaHorizontal * Math.Sin(this.angle), -this.transformOrigin.X * deltaHorizontal * Math.Sin(this.angle)); this._designerItem.Width -= deltaHorizontal; //element.Size.Width -= deltaHorizontal; break; default: break; } } e.Handled = true; }
/// <summary> /// /// </summary> /// <param name="c">UserControl</param> /// <param name="location"></param> void AddDesignerItem(object c, Point location) { DesignerItem designerItem = new DesignerItem(c); this.Children.Add(designerItem); IDesigner idr = designerItem.Content as IDesigner; DesignerVisualElement dc = idr.GetDesignerModel() as DesignerVisualElement; Binding canvasLeft = new Binding("Position.Location.X") { Source = dc }; designerItem.SetBinding(Canvas.LeftProperty, canvasLeft); Binding canvasTop = new Binding("Position.Location.Y") { Source = dc }; designerItem.SetBinding(Canvas.TopProperty, canvasTop); Binding canvasZIndex = new Binding("Position.ZIndex") { Source = dc }; designerItem.SetBinding(Canvas.ZIndexProperty, canvasZIndex); Binding widthBind = new Binding("Size.Width") { Source = dc, Mode = BindingMode.TwoWay }; designerItem.SetBinding(WidthProperty, widthBind); Binding heightBind = new Binding("Size.Height") { Source = dc, Mode = BindingMode.TwoWay }; designerItem.SetBinding(HeightProperty, heightBind); dc.Position.MoveTo(location.X, location.Y); this.DeselectAll(); designerItem.IsSelected = true; this.SelectItem = designerItem; }
private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e) { if (this._beMovedItem != null && this._parent != null && this._beMovedItem.IsSelected) { Point dragDelta = new Point(e.HorizontalChange, e.VerticalChange); Point offsetPoint = new Point(dragDelta.X, dragDelta.Y); if (_transform != null) { offsetPoint = _transform.Transform(offsetPoint); } foreach (DesignerItem item in this._parent.SelectedItems) { DesignerVisualElement dc = (item.Content as IDesigner).GetDesignerModel() as DesignerVisualElement; dc.Position.MoveOffset(offsetPoint.X, offsetPoint.Y); // DesignerCanvas.SetLeft(item, DesignerCanvas.GetLeft(item) + ); //DesignerCanvas.SetTop(item, DesignerCanvas.GetTop() + ); } this._parent.InvalidateMeasure(); e.Handled = true; } }