Snap to grid when dropping new item

2 posts, 0 answers
  1. Gijs
    Gijs avatar
    4 posts
    Member since:
    Sep 2014

    Posted 02 Feb 2015 Link to this post


    I have a toolbox with custom shapes. I have a grid with snapping to grid enabled.
    Once shapes are on the grid, they snap fine when I drag them.
    But they don't snap the first time, when I drag shapes from the toolbox.

    I would like to achieve this. Is there some setting I'm missing? Or would I have to implement a custom Snapping Service maybe?

    Thanks for any input.
  2. Zarko
    Zarko avatar
    755 posts

    Posted 04 Feb 2015 Link to this post

    Hi Gijs,
    By default we don't snap the drop position but you can change this using the ItemsChanged event:
    private void OnDiagramItemsChanged(object sender, DiagramItemsChangedEventArgs e)
        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            var shapService = this.diagram.ServiceLocator.GetService<ISnappingService>();
            foreach (var item in e.NewItems)
                var container = this.diagram.ContainerGenerator.ContainerFromItem(item) as IShape;
                if (container != null)
                    var newPosition = shapService.SnapPoint(container.Position);
                    container.Position = newPosition;
    I hope I was able to help you and if you have more questions feel free to ask.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top