protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) dragStartPoint = null; if (dragStartPoint.HasValue) { // XamlWriter.Save() has limitations in exactly what is serialized, // see SDK documentation; short term solution only; var xamlString = XamlWriter.Save(Content); var dataObject = new DragObject(); dataObject.Xaml = xamlString; var panel = VisualTreeHelper.GetParent(this) as WrapPanel; if (panel != null) { // desired size for DesignerCanvas is the stretched Toolbox item size var scale = 1.3; dataObject.DesiredSize = new Size(panel.ItemWidth*scale, panel.ItemHeight*scale); } DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); e.Handled = true; } }
private void UIElement_OnMouseMove(object sender, MouseEventArgs e) { OnMouseMove(e); var senderFrameworkElement = sender as FrameworkElement; if (senderFrameworkElement == null) { return; } if (e.LeftButton == MouseButtonState.Pressed) { // Package the data. var vm = senderFrameworkElement.DataContext as InitialElementViewModel; if (vm == null) { return; } //DataObject data = new DataObject(); //data.SetData(DataFormats.StringFormat, vm.Name); ////data.SetData("Double", circleUI.Height); //data.SetData("Object", vm); //data.SetText(vm.Name); //data.SetText(); //var data = new DataObject(); //// Inititate the drag-and-drop operation. //DragDrop.DoDragDrop(this, data, DragDropEffects.Copy | DragDropEffects.Move); var dataObject = new DragObject(); dataObject.Xaml = string.Empty; dataObject.InitialElementViewModel = vm; var panel = VisualTreeHelper.GetParent(this) as WrapPanel; if (panel != null) { // desired size for DesignerCanvas is the stretched Toolbox item size var scale = 1.3; dataObject.DesiredSize = new Size(panel.ItemWidth*scale, panel.ItemHeight*scale); } else { dataObject.DesiredSize = new Size(100, 100); } DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); e.Handled = true; } }