There is a telerik blog that shows how to implement autoscrolling when dragging items of a RadTreeView control using a behavior. I tried to adapt this to use with a RadTreeListView control but couldn't get it to work. Any idea of how to adapt it or of another approach?
Thanks,
Luzius
6 Answers, 1 is accepted
There are some minor differences between the TreeView and the TreeListView components. You have to make a few adjustments to the behavior presented in the blog post in order to use it with RadTreeListView.
For starters, the type of the Behavior from which the AutoScrollBehavior derives should be RadTreeListView. Than instead of ScrollViewer, you should look for GridViewScrollViewer since this is the one that the GridViewDataControls use.
In the end this is how it should look like:
public
class
TreeListAutoScrollBehavior : Behavior<RadTreeListView>
{
protected
override
void
OnAttached()
{
base
.OnAttached();
EventManager.RegisterClassHandler(
typeof
(GridViewScrollViewer), RadDragAndDropManager.DropQueryEvent,
new
EventHandler<DragDropQueryEventArgs>(OnTreeListViewScrollViewerDropQuery),
true
);
}
private
static
void
OnTreeListViewScrollViewerDropQuery(
object
sender, DragDropQueryEventArgs e)
{
var scrollViewer = sender
as
GridViewScrollViewer;
if
(scrollViewer !=
null
)
{
var currentDragPoint = e.Options.CurrentDragPoint;
var generalTransform = scrollViewer.TransformToVisual(Application.Current.RootVisual);
var topLeft = generalTransform.Transform(
new
Point(0, 0));
var relative =
new
Point(currentDragPoint.X - topLeft.X, currentDragPoint.Y - topLeft.Y);
if
(relative.Y > 0 && relative.Y < 40)
{
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - (20 * ((40 - relative.Y) / 40)));
}
if
(relative.Y > scrollViewer.ActualHeight - 40 && relative.Y < scrollViewer.ActualHeight)
{
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + (20 * ((40 - (scrollViewer.ActualHeight - relative.Y)) / 40)));
}
if
(relative.X > 0 && relative.X < 40)
{
scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset - (20 * ((40 - relative.X) / 40)));
}
if
(relative.X > scrollViewer.ActualWidth - 40 && relative.X < scrollViewer.ActualWidth)
{
scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + (20 * ((40 - (scrollViewer.ActualWidth - relative.X)) / 40)));
}
}
}
}
Hope this helps! Regards,
Nik
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
It's working now. The GridViewScrollViewer instead of the ScrollViewer was the missing piece in my adaption.
Thanks,
Luzius
Thanks
This code works perfect, but now we are migrating the raddraganddropmanager to the dragdropmanager.
What event should we use instead of the RadDragAndDropManager.DropQueryEvent in the following code ?
EventManager.RegisterClassHandler(typeof(GridViewScrollViewer), RadDragAndDropManager.DropQueryEvent, new EventHandler<
DragDropQueryEventArgs
>(OnTreeListViewScrollViewerDropQuery), true);
Thanks Sodi We
You can look into this thread to see how you can do the same with DragDropManager.
Hope it helps!
Nik
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I found the solution in the thread you gave.
Thanks
Sodi We