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

Polygon dragging.

1 Answer 54 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 06 Mar 2009, 06:37 PM
Hi First post here..

I have started playing around with the drag and drop functionnality.

So far I am able to drag around on a canvas dynamically drawn Rectangle.

Problem is when i try to do the same on Polygons (triangle)

When I click to pick up the polygon, it just to the right and botton a bit... out of the mouse click range.. all tries have same behavior until polygon has moved itself out of the canvas (right - bottom)

The code i use is there.


Partial Public Class DragDrop
    Inherits UserControl
    Private myPageSwitch As PageSwitch

    Public Sub New(ByVal ps As PageSwitch)
        InitializeComponent()

        myPageSwitch = ps


        Me.dropCanvas.[AddHandler](RadDragAndDropManager.DragQueryEvent, New EventHandler(Of DragDropQueryEventArgs)(AddressOf OnDragQuery))
        Me.dropCanvas.[AddHandler](RadDragAndDropManager.DropQueryEvent, New EventHandler(Of DragDropQueryEventArgs)(AddressOf OnDropQuery))

        'BuildRect()
        BuildTriangle()


        'For i As Integer = 1 To 4
        '    CreateARectangle(50, 50, 0, 0, Colors.Red)
        'Next


    End Sub

    Private Sub OnDragQuery(ByVal sender As Object, ByVal e As DragDropQueryEventArgs)
        If e.Options.Status = DragStatus.DragQuery Then
            e.QueryResult = True
            e.Handled = True
        End If

        If e.Options.Status = DragStatus.DropSourceQuery Then
            e.QueryResult = True
            e.Handled = True
        End If
    End Sub

    Private Sub OnDropQuery(ByVal sender As Object, ByVal e As DragDropQueryEventArgs)
        If e.Options.Status = DragStatus.DropDestinationQuery Then
            e.QueryResult = True

            'Get the image:
            Dim image = TryCast(e.Options.Source, FrameworkElement)

            'Get where the canvas is located relative to the root:
            Dim canvasPosition = dropCanvas.TransformToVisual(Nothing).Transform(New Point(0, 0))
            Dim mousePosition = e.Options.CurrentDragPoint

            'Move the image accordingly:
            Canvas.SetLeft(image, mousePosition.X - canvasPosition.X - image.ActualWidth / 2)
            Canvas.SetTop(image, mousePosition.Y - canvasPosition.Y - image.ActualHeight / 2)
        End If
    End Sub

    Sub BuildTriangle()
        Dim pol As New Polygon
        With pol
            .Stroke = New SolidColorBrush(Colors.Black)
            .Fill = New SolidColorBrush(Colors.Green)
            .Points.Add(New Point(20, 60))
            .Points.Add(New Point(60, 80))
            .Points.Add(New Point(80, 20))
        End With



        RadDragAndDropManager.SetAllowDrag(pol, True)
        RadDragAndDropManager.SetAllowDrop(pol, True)

        dropCanvas.Children.Add(pol)

    End Sub


Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 13 Mar 2009, 09:53 AM
Hi Fred,

First, sorry for the delayed answer. We have been busy with the Q1 release. Your feedback is welcome!

Now, the DragDrop:

It is best not to set drag/drop properties in the constructor of the root visual element since the DragDrop needs the root visual element for initialization.

Also, the drag does not go very smoothly, because the path is set as a drop target, while it is best to set the canvas as a drop target.

It seems that the path will always return it's actual size as (0,0) which is not very helpful. This is why the path will always appear to be dragged by its lower right edge. I guess that it is best to calculate its size as you create it and  then refer to it as you drag it.

Sincerely yours,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
DragAndDrop
Asked by
Fred
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or