Hey
There is an issue if i would like to get the left-top position of the dragcue. In the case i declare a control as a drag and drop container the "TranformToVisual" Method is crashing with an exception "The value is outside of the expected range".
private void dropBox_DropQuery(object sender, DragDropQueryEventArgs e)
{
var topLeft = (e.Options.DragCue as FrameworkElement).TransformToVisual(null).Transform(new Point(0, 0));
e.QueryResult = true;
e.Handled = true;
}
Best regards Holger
There is an issue if i would like to get the left-top position of the dragcue. In the case i declare a control as a drag and drop container the "TranformToVisual" Method is crashing with an exception "The value is outside of the expected range".
private void dropBox_DropQuery(object sender, DragDropQueryEventArgs e)
{
var topLeft = (e.Options.DragCue as FrameworkElement).TransformToVisual(null).Transform(new Point(0, 0));
e.QueryResult = true;
e.Handled = true;
}
Best regards Holger
6 Answers, 1 is accepted
0
Hello Cooltisch,
Attached you can find a sample project. Inside a RadWrapPanel I put a rectangle which you can drag and drop on the Canvas next to it. Also I added the line of code which causes you problems. Review the project and feel free to ask me if you have further questions.
Greetings,
Viktor Tsvetkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Attached you can find a sample project. Inside a RadWrapPanel I put a rectangle which you can drag and drop on the Canvas next to it. Also I added the line of code which causes you problems. Review the project and feel free to ask me if you have further questions.
Greetings,
Viktor Tsvetkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Holger
Top achievements
Rank 1
answered on 09 Jun 2010, 06:25 AM
Thanks for your answer and your example.
As long as you drag an object from another control/container it works perfect.
Please change your XAML like that:
<Canvas x:Name="canvas" Grid.Column="1" Background="Black" Height="500" Width="1000" telerikDragDrop:RadDragAndDropManager.AllowDrop="True">
<Rectangle Width="100" Height="100" Fill="Red" x:Name="rectangle" telerikDragDrop:RadDragAndDropManager.AllowDrag="True" />
</Canvas>
Just move the rectangle inside of the canvas and your solution does not work any more and this code line
"var canvasPosition = (e.Options.DragCue as FrameworkElement).TransformToVisual(null).Transform(new Point(0, 0));"
will throw an exception.
As long as you drag an object from another control/container it works perfect.
Please change your XAML like that:
<Canvas x:Name="canvas" Grid.Column="1" Background="Black" Height="500" Width="1000" telerikDragDrop:RadDragAndDropManager.AllowDrop="True">
<Rectangle Width="100" Height="100" Fill="Red" x:Name="rectangle" telerikDragDrop:RadDragAndDropManager.AllowDrag="True" />
</Canvas>
Just move the rectangle inside of the canvas and your solution does not work any more and this code line
"var canvasPosition = (e.Options.DragCue as FrameworkElement).TransformToVisual(null).Transform(new Point(0, 0));"
will throw an exception.
0
Hello Cooltisch,
Attached is the edited project. You need to move this problematic line of code in the OnDropInfo method. Please review it and do not hesitate to get back to me if you have further questions.
Greetings,
Viktor Tsvetkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Attached is the edited project. You need to move this problematic line of code in the OnDropInfo method. Please review it and do not hesitate to get back to me if you have further questions.
Greetings,
Viktor Tsvetkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Holger
Top achievements
Rank 1
answered on 10 Jun 2010, 11:47 AM
Hey Viktor
this doesn't work either. I placed the following line inside of the Dropinfo event.
private void OnDropInfo(object sender, DragDropEventArgs e)
{
//This line throws an exception
var myPosition = (e.Options.DragCue as FrameworkElement).TransformToVisual(null).Transform(new Point(0, 0));
var destination = e.Options.Destination;
if (e.Options.Status == DragStatus.DropComplete && destination is Canvas)
{
var payload = e.Options.Payload as FrameworkElement;
var canvasPosition = canvas.TransformToVisual(null).Transform(new Point(0, 0));
var mousePosition = e.Options.CurrentDragPoint;
Canvas.SetLeft(payload, mousePosition.X - canvasPosition.X - payload.ActualWidth / 2);
Canvas.SetTop(payload, mousePosition.Y - canvasPosition.Y - payload.ActualHeight / 2);
var newChild = e.Options.Payload as Rectangle;
canvas.Children.Add(newChild);
}
}
Best regards Holger
this doesn't work either. I placed the following line inside of the Dropinfo event.
private void OnDropInfo(object sender, DragDropEventArgs e)
{
//This line throws an exception
var myPosition = (e.Options.DragCue as FrameworkElement).TransformToVisual(null).Transform(new Point(0, 0));
var destination = e.Options.Destination;
if (e.Options.Status == DragStatus.DropComplete && destination is Canvas)
{
var payload = e.Options.Payload as FrameworkElement;
var canvasPosition = canvas.TransformToVisual(null).Transform(new Point(0, 0));
var mousePosition = e.Options.CurrentDragPoint;
Canvas.SetLeft(payload, mousePosition.X - canvasPosition.X - payload.ActualWidth / 2);
Canvas.SetTop(payload, mousePosition.Y - canvasPosition.Y - payload.ActualHeight / 2);
var newChild = e.Options.Payload as Rectangle;
canvas.Children.Add(newChild);
}
}
Best regards Holger
0
Hi Cooltisch,
Can you please elaborate on your scenario a bit more? That will help us provide you with a better suited solution.
Also, you can get the position in the OnDragInfo() event handler when the DragStatus is DragInProgress, like so:
I attached a modified project illustrating the suggested approach. Please take a look at it and let me know if it works for you or if your scenario requires a different approach.
Regards,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Can you please elaborate on your scenario a bit more? That will help us provide you with a better suited solution.
Also, you can get the position in the OnDragInfo() event handler when the DragStatus is DragInProgress, like so:
private void OnDragInfo(object sender, DragDropEventArgs e)
{
if (e.Options.Status == DragStatus.DragInProgress)
{
var myPosition = (e.Options.DragCue as FrameworkElement).TransformToVisual(null).Transform(new Point(0, 0));
}
if (e.Options.Status == DragStatus.DragComplete)
{
canvas.Children.Remove(e.Source as UIElement);
}
}
I attached a modified project illustrating the suggested approach. Please take a look at it and let me know if it works for you or if your scenario requires a different approach.
Regards,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Matthew
Top achievements
Rank 1
answered on 13 Apr 2011, 05:42 AM
This is a great example. Is it possible to use a Canvas object as the DragCue instead of a Rectangle? I have seen examples where Rectangles and Image are used. However, I would like to use a Canvas. An example would be great.
Thanks,
Matt
Thanks,
Matt