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

Shape DragEnter doesn't work like ContainerShape does

2 Answers 66 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
seokhyun
Top achievements
Rank 1
Veteran
seokhyun asked on 18 Feb 2020, 02:56 AM
"Shape" DragEnter doesn't work like "ContainerShape" does



RadDiagramContainerShape has OnDragEnter Event. so, on Diagram, if i drag shape into Containershape then DragEnter, DragOver, DragLeave are worked.

but Shape doesn't have DragEnter and DragOver. 



i want to do senario that when "Shape" is dragged to other "Shape", other "Shape"'s DragEnter event is activated.



i handled DragEnter on "Shape",

"DragDropManager.AddDragEnterHandler(this, MyDragEnterEventMethod);"



but, MyDragEnterEventMethod doesn't work when "Shape" is dragged to other "Shape" on Diagram.

MyDragEnterEventMethod only work when control DragContent to DragDropManager.AddDragInitializeHandler.



DragDropManager.AddDragInitializeHandler Code is below

DragDropManager.AddDragInitializeHandler(this.diagram, OnDragSourceDragInitialize);



and OnDragSourceDragInitialize Code is below

private void OnDragSourceDragInitialize(object sender, DragInitializeEventArgs e)
        {
            this.dragVisualControl.Content = this.PrepareDragVisualTypeB(e.OriginalSource as RadDiagramShape);
            e.DragVisual = this.dragVisualControl;
            e.DragVisualOffset = e.RelativeStartPoint;
            e.AllowedEffects = DragDropEffects.All;
        }

Shape DragEnter doesn't work like ContainerShape does

 

RadDiagramContainerShape has OnDragEnter Event. so, on Diagram, if i drag shape into Containershape then DragEnter, DragOver, DragLeave are worked.

but Shape doesn't have DragEnter and DragOver. 

 

i want to do senario if shape is dragged to other shape then other shape's DragEnter event is activated.

 

i tried to handle DragEnter on shape,

"DragDropManager.AddDragEnterHandler(this, MyDragEnterEventMethod);" in Customshape implements RadDiagramShape,

 

but, MyDragEnterEventMethod doesn't work when shape is dragged to other shape on Diagram.

MyDragEnterEventMethod only work when control DragContent to DragDropManager.AddDragInitializeHandler.

 

DragDropManager.AddDragInitializeHandler Code is below

DragDropManager.AddDragInitializeHandler(this.diagram, OnDragSourceDragInitialize);

 

and OnDragSourceDragInitialize Code is below

private void OnDragSourceDragInitialize(object sender, DragInitializeEventArgs e)
        {
            this.dragVisualControl.Content = this.PrepareDragVisualTypeB(e.OriginalSource as RadDiagramShape);
            e.DragVisual = this.dragVisualControl;
            e.DragVisualOffset = e.RelativeStartPoint;
            e.AllowedEffects = DragDropEffects.All;
        }

 

How do i Activate Shape DragEnter, DragOver, DragLeave like ContainerShape does?

i need to cases

case 1. when it dragged "Shape1" to "Shape2", "Shape2"'s Drag Enter is activated.

case 2. when it dropped "Shape1" to "Shape2", "Shape2"'s Drop Event  is activated.

2 Answers, 1 is accepted

Sort by
0
seokhyun
Top achievements
Rank 1
Veteran
answered on 24 Feb 2020, 12:46 AM

hm.. i found DraggingService.DragOverShape.

But DragOverShape only works on ContainerShape too.

How do i get a DragOverShape also RadDiagramShape?

0
Petar Mladenov
Telerik team
answered on 26 Feb 2020, 02:10 PM

Hello seokhyun,

The RadDiagram's drag drop feature does not use WPF drag/drop events nor DragDropManager's ones. It internally has DraggingService which organizes the drag drop logic (by manually handling mouse events and performing hit-testing under mouse). Also drop is primarily focused on containers which implement IDragDropAware interface. So one possible way to here is to make your normal shapes implement this interface. For more information on how to create custom shape in RadDiagram please check the following article:   

    Diagram Custom Shape Regards

However, there is also another way to detect that DraggingService is working (shape is being dragged) and there is shape under the mouse. The below code is somehow similar to what diagram does internally:

        DraggingService dragService;

        public MainWindow()
        {
            InitializeComponent();
            this.dragService = this.Diagram.ServiceLocator.GetService<IDraggingService>() as DraggingService;
            if (dragService != null)
            {
                dragService.Dragging += DragService_Dragging;
            }
        }

        private void DragService_Dragging(object sender, PositionChangedEventArgs e)
        {
            var notDraggedShapesUnderPoint = this.Diagram.Shapes
                .Where(x => !x.IsSelected && 
                             x.IsEnabled && 
                             x.Visibility == Visibility.Visible && 
                             x.Bounds.Contains(e.OldPosition, x.RenderTransformOrigin, x.RotationAngle));
           
            var dropAwareShape = notDraggedShapesUnderPoint.OrderBy(x => x.ZIndex).LastOrDefault();

            if (dropAwareShape != null)
            {
                
            }
        }

The last if clause can be used as an entry point and you can also fire a custom event there. However, for more precise work over the dragging service I would encourage you to inherit it and so you can better utilize protected members and change the logic easier.

Dragging Serice

Diagram Custom Services SDK

,
Petar Mladenov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Diagram
Asked by
seokhyun
Top achievements
Rank 1
Veteran
Answers by
seokhyun
Top achievements
Rank 1
Veteran
Petar Mladenov
Telerik team
Share this question
or