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

Lock Position

2 Answers 132 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Maurício
Top achievements
Rank 1
Maurício asked on 01 Apr 2015, 06:57 PM
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 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 02 Apr 2015, 07:58 AM
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.

 
0
Maurício
Top achievements
Rank 1
answered on 02 Apr 2015, 11:01 AM
Hello Martin,

Thank you for your quick answer, it solved the problem.
Tags
Diagram
Asked by
Maurício
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Maurício
Top achievements
Rank 1
Share this question
or