Drag event in a diagram

1 Answer 102 Views
Diagram DragAndDrop
Pete
Top achievements
Rank 2
Iron
Iron
Iron
Pete asked on 02 Sep 2021, 12:52 PM

When selected objects, like shapes and links between the shapes are dragged, if they are selected they all move together as a group as expected. At the end of the drag, a Drag event is generated and in the DragRoutedEventArgs there's an Items list which indicates which items have been dragged, and in some cases the new position.

If the item being dragged is a shape, then I see a IDragItem with a position value.

If the items is a connection between say two shapes dragged, then I see another IDragItem, however, it's position is always 0, 0

The problem I have is that if the connection is a straight line between shapes then it works fine. However, if the connection has extra points added by the user, then I don't get told about those points. So how do I update the data behind about those points?

Dragging the shapes in the view is working correctly, however there's missing data, so if I save and restore, the extra connection points weren't updated so they show the old position. I'll attach a diagram of what I mean.

1 Answer, 1 is accepted

Sort by
1
Accepted
Vladimir Stoyanov
Telerik team
answered on 07 Sep 2021, 09:51 AM

Hello Pete,

Thank you for the shared picture. 

I tried to replicate the described scenario on my end, however I was not able to do so. That is why I am attaching the sample project that I used for testing purposes. On my end, the Position property of a dragged connection is updated correctly. I was also not able to replicate the save/restore behavior. 

May I ask you to check out the shared project to see, if you can reproduce the observed on your end result? If that is the case, can you share a video so that I can get a better understanding and further assist you? You can also modify the project, if necessary and send it back.

Thank you in advance for any help you can provide.

Regards,
Vladimir Stoyanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Pete
Top achievements
Rank 2
Iron
Iron
Iron
commented on 09 Sep 2021, 04:06 PM | edited

If I use the following, I get 0, 0 printed (EDIT: just realised - there's a Content being used here)

foreach(IDiagramItem item in args.Items)
{
	if (item.Content is LinkViewModel link)
        {
		Trace.WriteLine($"position {link.Position}");
	}
 }

If I use this (based on your code), I get a position:

var connections = args.Items.OfType<RadDiagramConnection>();
foreach(var connection in connections)
{
	Trace.WriteLine(connection.Position);
}
Seems like using a IDiagramItem means you get a 0,0 position while dragging?
Pete
Top achievements
Rank 2
Iron
Iron
Iron
commented on 10 Sep 2021, 09:13 AM

Got it! This is what I needed:


// Deal with extra points on connections moving
var connections = args.Items.OfType<RadDiagramConnection>();
foreach(var connection in connections)
{
	var link = connection.Content as LinkViewModel;
	int index = 0;
        foreach(var point in connection.ConnectionPoints)
        {
		// ...get link to update position of point...
        }
}

Vladimir Stoyanov
Telerik team
commented on 14 Sep 2021, 02:26 PM

I am glad to hear that you were able to achieve what you were going for.

Thank you for sharing your approach. 

Tags
Diagram DragAndDrop
Asked by
Pete
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or