Snap to grid when previewing & dropping new item

3 posts, 0 answers
  1. Tim Johnson
    Tim Johnson avatar
    11 posts
    Member since:
    Dec 2009

    Posted 08 Nov Link to this post

    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. Tim Johnson
    Tim Johnson avatar
    11 posts
    Member since:
    Dec 2009

    Posted 09 Nov in reply to Tim Johnson Link to this post

    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;
        }
    }
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tim Johnson
    Tim Johnson avatar
    11 posts
    Member since:
    Dec 2009

    Posted 09 Nov in reply to Tim Johnson Link to this post

    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. 

Back to Top