10 Answers, 1 is accepted
Hello Wu,
Can you check out the Restrict the Draggable Area article in our documentation? It demonstrates how to limit the area, where a shape can be dragged.
I hope you find this helpful.
Regards,
Vladimir Stoyanov
Progress Telerik
Hi Wu,
Can you check out the How to prevent dragging out of shapes from container forum thread, where a similar question was discussed? The approach from the article linked in my previous reply is adapted inside the attached project to prevent dragging out of the parent container.
Regards,
Vladimir Stoyanov
Progress Telerik
I holp limit move the shape exceed the container range(yes, the above demo Realized),
but can't limit the shape move from one container to another,
the above demo also limit move the shape between two Containers,
In practice,the shape must exist parent container,but can change the parent container from one to another.
Hello Wu,
Thank you for the update.
It seems to me that the notion of limiting the dragging of a shape within its container contradicts with the functionality of being able to drag a shape from one parent container to another. Can you share how you envision this functionality? You can send over some sample pictures/videos of the expected behavior.
Regards,
Vladimir Stoyanov
Progress Telerik
for example,can't drag the TreeViewItem to the spare area(like can't position the diagram shape outside the container ),
but can drop to the other RadTreeView object(like from one container to the another).
Hello Wu,
I am attaching a sample project that demonstrates a possible way of achieving the described functionality. It uses the PreviewDrag and Drag events of the RadDiagram along with the Drop event of the DraggingService.
Of course, feel free to adapt or extend the approach so that it suits your exact scenario.
Regards,
Vladimir Stoyanov
Progress Telerik
there is a small problem:after moving the shape to the spare area,then the shape return to previous positions automatic,
but the shape don't belongs to its parent container,so when moving the parent container,the shape will not move follow
Hello Wu,
Indeed there is logic in the RadDiagram that removes the shape once it is dropped outside of the container. There isn't a convenient way to modify this as the logic is private to the DraggingTool.
I am attaching the sample project modified to demonstrate how you can extract and update the source code of the DraggingTool in order to prevent the removal of the child shape from the parent container (in scenarios where a drop is attempted on the diagram surface). It involves modifying the CompleteDrag method of the DraggingTool and I have included a comment, in the place where I introduced a change.
Note, that the demonstrated approach is a customization and I have not tested it extensively. That said, I do hope that you will find it useful as a starting point. Of course, feel free to adapt the demonstrated approach to your exact scenario.
Regards,
Vladimir Stoyanov
Progress Telerik
thank you very much!
Before that,I save the shape's parent Container like your code which save the shape's position,
then add agian:
shapeParentContainer[shape.GetHashCode()].AddItem(shape);
maybe your method is better.