Lock Position

3 posts, 0 answers
  1. Maurício
    Maurício avatar
    41 posts
    Member since:
    Jan 2011

    Posted 01 Apr 2015 Link to this post

    Hello

    Is there a way to lock a radDiagramItem so the user won't be able to move it?

    I've already disabled the item's dragging, but the user can still  change the position through Ctrl+Arrow Keys.
  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 02 Apr 2015 Link to this post

    Hello Maurício,

    In order to stop the nudge operation (moving of the shapes through Ctrl+Arrow) you can subscribe for the diagram's PreviewKeyDown event and handle it if the shape should not be moved. Here is an example:
    void diagram_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        bool isArrowKeyPressed = (e.Key == Key.Left) ||
            (e.Key == Key.Right) ||
            (e.Key == Key.Up) ||
            (e.Key == Key.Down);
     
        bool isCtrlDown = Keyboard.Modifiers == ModifierKeys.Control;
     
        if (isArrowKeyPressed && isCtrlDown)
        {
            var selectedItems = this.diagram.SelectedItems.OfType<IDiagramItem>();
            foreach (var item in selectedItems)
            {
                if (!item.IsDraggingEnabled)
                {
                    e.Handled = true;
                    return;
                }
            }
        }
    }

    Please try this and let me know if it helps.

    Regards,
    Martin
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Maurício
    Maurício avatar
    41 posts
    Member since:
    Jan 2011

    Posted 02 Apr 2015 in reply to Martin Link to this post

    Hello Martin,

    Thank you for your quick answer, it solved the problem.
Back to Top