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

Custom shape drag / select events

2 Answers 134 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 23 Apr 2015, 11:17 PM

I have a custom usercontrol that is replacing the ContentTemplate for a RadDiagramShape. This usercontrol has a listbox containing other usercontrols.

I'm wondering how I can have the RadDiagram drag and selection events captured for the parent shape when clicking on items in the inner listbox?

 

Thanks

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 28 Apr 2015, 12:55 PM
Hello Terry,

The described requirement is not supported out of the box and it requires customization in order to be achieved - which is not very straightforward task. However, I can give you couple ideas on how to achieve the desired functionality.
  • To sync the selection you can use the UIElement.AddHandler() method to subscribe for the SelectionChanged event of all ListBox elements in the diagram and inside the event handler use the SelectionService of the diagram to select the parent shape that holds the list box. Here is an example:
    public MainWindow()
    {
        // other code
        this.diagram.AddHandler(ListBox.SelectionChangedEvent, new SelectionChangedEventHandler(listBox_SelectionChanged));
    }

    private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var listBox = (ListBox)e.OriginalSource;
        var service = this.diagram.ServiceLocator.GetService<ISelectionService<IDiagramItem>>() as SelectionService;
        var shape = listBox.ParentOfType<RadDiagramShape>();
        service.SelectItem(shape);
    }
  • On the other hand the dragging will require some additional implementation. For example you can subscribe for the MouseMove event of the diagram and implement custom drag when the mouse is over the ListBox element.
    void diagram_MouseMove(object sender, MouseEventArgs e)
    {     
        var draggingService = this.diagram.ServiceLocator.GetService<IDraggingService>() as DraggingService;       
        if (e.LeftButton == MouseButtonState.Pressed && !draggingService.IsDragging)
        {
            var shape = this.diagram.SelectedItem as RadDiagramShapeBase;
            if (shape != null && shape.IsMouseOver)
            
                // get the mouse position and translate it to diagram position using the diagram's GetTransformedPoint() method
                // calculate the shape's new position based on the mouse's new and the old coordinates         
                // set the new position to on the shape's Position property - shape.Position = newPosition
            }
        }
    }
Please try those approaches and let me know if they work for you.

Regards,
Martin
Telerik
 

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

 
0
Terry
Top achievements
Rank 1
answered on 30 Apr 2015, 09:13 PM
Thank you. This does give me some ideas on how to move forward
Tags
Diagram
Asked by
Terry
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Terry
Top achievements
Rank 1
Share this question
or