This is a migrated thread and some comments may be shown as answers.

Snap to grid when previewing & dropping new item

2 Answers 91 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Tim Johnson
Top achievements
Rank 1
Tim Johnson asked on 08 Nov 2016, 04:59 PM

I have a ListBox with shapes that I am dragging onto a RadDiagram.  The snapping works when an item is dropped on the diagram, thanks to this post --> http://www.telerik.com/forums/snap-to-grid-when-dropping-new-item.

However, I would also like the same functionality to work when previewing this drop ( add the alignment lines and preview where the shape will be snapped to )

Is there any way implement this snap preview? Any feedback would be helpful.

2 Answers, 1 is accepted

Sort by
0
Tim Johnson
Top achievements
Rank 1
answered on 09 Nov 2016, 11:41 PM

I was able to fix my issue with the following:

private void DragDropManager_DragEnter(object sender, DragEventArgs e){
    var shapeItem = this.Shapes.FirstOrDefault(s => s.Content == this.DraggedBlockModel);
    var shapes = this.Shapes.Where(s => s != shapeItem);
    SnapService.InitializeSnap(shapes, shapeItem, true, false, currentPosition);
}
 
private void DragDropManager_DragOver(object sender, DragEventArgs e)
{
    var shapeItem = this.Shapes.FirstOrDefault(s => s.Content == this.DraggedBlockModel);
    var currentPosition = this.GetTransformedPoint(e.GetPosition(this));
    var newPosition = SnapService.SnapItems(new[] {shapeItem}, currentPosition);
    if (shapeItem != null)
    {
        shapeItem.Position = newPosition;
    }
}
0
Tim Johnson
Top achievements
Rank 1
answered on 09 Nov 2016, 11:48 PM

I forgot to mention that I also added the shape to the page on DragEnter and hid the drag visual. So as soon as I dragged a shape onto the page, the shape was added, and I could move the shape based on my mouses position. 

Tags
Diagram
Asked by
Tim Johnson
Top achievements
Rank 1
Answers by
Tim Johnson
Top achievements
Rank 1
Share this question
or