Here i am trying to add behavior to my ScrollViewer in WPF, where when i am dragging anything to ItemsControl and list is longer than User should be able to drag that item to end of the list and list should scroll automaticall.
Following code will include drag/scroll behavior in ScrollViewer!
public class DragBehavior : Behavior
{
const double Tolerance = 100;
const double Offset = 10;
protected override void OnAttached()
{
var svFavourites = AssociatedObject;
AssociatedObject.DragOver += (sender, e) =>
{
var verticalPos = e.GetPosition(svFavourites).Y;
if (verticalPos < Tolerance)
{
svFavourites.ScrollToVerticalOffset(svFavourites.VerticalOffset - Offset);
}
else if (verticalPos > svFavourites.ActualHeight - Tolerance)
{
svFavourites.ScrollToVerticalOffset(svFavourites.VerticalOffset + Offset);
}
};
}
}
To use the above Behavior just add following inside ScrollViewer in XAML
Following code will include drag/scroll behavior in ScrollViewer!
public class DragBehavior : Behavior
{
const double Tolerance = 100;
const double Offset = 10;
protected override void OnAttached()
{
var svFavourites = AssociatedObject;
AssociatedObject.DragOver += (sender, e) =>
{
var verticalPos = e.GetPosition(svFavourites).Y;
if (verticalPos < Tolerance)
{
svFavourites.ScrollToVerticalOffset(svFavourites.VerticalOffset - Offset);
}
else if (verticalPos > svFavourites.ActualHeight - Tolerance)
{
svFavourites.ScrollToVerticalOffset(svFavourites.VerticalOffset + Offset);
}
};
}
}
To use the above Behavior just add following inside ScrollViewer in XAML