Skip to content

Snap on/after/during draw #354

Answered by zHaytam
rjtwins asked this question in Q&A
Sep 24, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Currently, there is no out of the box to do that, however you can just re-set the position of all your nodes while while snapping it with the following snippet of code:

yourNode.SetPosition(new Point(ApplyGridSize(yourNode.Position.X), ApplyGridSize(yourNode.Position.Y));

private double ApplyGridSize(double n)
{
    if (Diagram.Options.GridSize == null)
        return n;

    var gridSize = Diagram.Options.GridSize.Value;
    return gridSize * Math.Floor((n + gridSize / 2.0) / gridSize);
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rjtwins
Comment options

Answer selected by rjtwins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants