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
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