private void MoveThumb_DragStarted(object sender, DragStartedEventArgs e) { designerItem = DataContext as DesignerItem; if (designerItem != null) { var pos = Mouse.GetPosition(designerItem); offsetX = pos.X; offsetY = pos.Y; } }
public ResizeRotateAdorner(DesignerItem designerItem) : base(designerItem) { SnapsToDevicePixels = true; chrome = new ResizeRotateControl { DataContext = designerItem }; visuals = new VisualCollection(this) { chrome }; }
private void RotateThumb_DragStarted(object sender, DragStartedEventArgs e) { designerItem = DataContext as DesignerItem; if (designerItem != null) { centerPoint = designerItem.TranslatePoint( new Point(designerItem.Width * designerItem.RenderTransformOrigin.X, designerItem.Height * designerItem.RenderTransformOrigin.Y), designerItem.DesignerCanvas); Point startPoint = Mouse.GetPosition(designerItem.DesignerCanvas); startVector = Point.Subtract(startPoint, centerPoint); } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); string xamlString = e.Data.GetData("DESIGNER_ITEM") as string; if (!String.IsNullOrEmpty(xamlString)) { DesignerItem newItem = null; if (XamlReader.Load(XmlReader.Create(new StringReader(xamlString))) is FrameworkElement content) { newItem = new DesignerItem { Content = content, DesignerCanvas = this }; var pos = e.GetPosition(this); if (content.MinHeight != 0 && content.MinWidth != 0) { newItem.Width = content.MinWidth * 2; newItem.Height = content.MinHeight * 2; } else { newItem.Width = DefaultValues.ItemDefaultWidth; newItem.Height = DefaultValues.ItemDefaultHeight; } DesignerCanvas.SetLeft(newItem, Math.Max(0, pos.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, pos.Y - newItem.Height / 2)); Children.Add(newItem); newItem.Position = new Point(DesignerCanvas.GetLeft(newItem), DesignerCanvas.GetTop(newItem)); DeselectAll(); newItem.IsSelected = true; } e.Handled = true; } }