Hello,
I am new to Infragistics and I like the tools and widgets you have.
I am using the XamDataGrid for my TouchPad. I want to gain access to the grid part as a scrollviewer, so that I can integrate my kinetic scrolling actions (dependency properties) for scrollviewer.
Below is my class for Kinetic Scrolling
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
namespace ScrollableArea
{
public class KineticBehaviour
#region Friction
/// <summary>
/// Friction Attached Dependency Property
/// </summary>
public static readonly DependencyProperty FrictionProperty =
DependencyProperty.RegisterAttached("Friction", typeof(double), typeof(KineticBehaviour),
new FrameworkPropertyMetadata((double)0.95));
/// Gets the Friction property. This dependency property
/// indicates ....
public static double GetFriction(DependencyObject d)
return (double)d.GetValue(FrictionProperty);
}
/// Sets the Friction property. This dependency property
public static void SetFriction(DependencyObject d, double value)
d.SetValue(FrictionProperty, value);
#endregion
#region ScrollStartPoint
/// ScrollStartPoint Attached Dependency Property
private static readonly DependencyProperty ScrollStartPointProperty =
DependencyProperty.RegisterAttached("ScrollStartPoint", typeof(Point), typeof(KineticBehaviour),
new FrameworkPropertyMetadata((Point)new Point()));
/// Gets the ScrollStartPoint property. This dependency property
private static Point GetScrollStartPoint(DependencyObject d)
return (Point)d.GetValue(ScrollStartPointProperty);
/// Sets the ScrollStartPoint property. This dependency property
private static void SetScrollStartPoint(DependencyObject d, Point value)
d.SetValue(ScrollStartPointProperty, value);
#region ScrollStartOffset
/// ScrollStartOffset Attached Dependency Property
private static readonly DependencyProperty ScrollStartOffsetProperty =
DependencyProperty.RegisterAttached("ScrollStartOffset", typeof(Point), typeof(KineticBehaviour),
/// Gets the ScrollStartOffset property. This dependency property
private static Point GetScrollStartOffset(DependencyObject d)
return (Point)d.GetValue(ScrollStartOffsetProperty);
/// Sets the ScrollStartOffset property. This dependency property
private static void SetScrollStartOffset(DependencyObject d, Point value)
d.SetValue(ScrollStartOffsetProperty, value);
#region InertiaProcessor
/// InertiaProcessor Attached Dependency Property
private static readonly DependencyProperty InertiaProcessorProperty =
DependencyProperty.RegisterAttached("InertiaProcessor", typeof(InertiaHandler), typeof(KineticBehaviour),
new FrameworkPropertyMetadata((InertiaHandler)null));
/// Gets the InertiaProcessor property. This dependency property
private static InertiaHandler GetInertiaProcessor(DependencyObject d)
return (InertiaHandler)d.GetValue(InertiaProcessorProperty);
/// Sets the InertiaProcessor property. This dependency property
private static void SetInertiaProcessor(DependencyObject d, InertiaHandler value)
d.SetValue(InertiaProcessorProperty, value);
#region HandleKineticScrolling
/// HandleKineticScrolling Attached Dependency Property
public static readonly DependencyProperty HandleKineticScrollingProperty =
DependencyProperty.RegisterAttached("HandleKineticScrolling", typeof(bool),
typeof(KineticBehaviour),
new FrameworkPropertyMetadata((bool)false,
new PropertyChangedCallback(OnHandleKineticScrollingChanged)));
/// Gets the HandleKineticScrolling property. This dependency property
public static bool GetHandleKineticScrolling(DependencyObject d)
return (bool)d.GetValue(HandleKineticScrollingProperty);
/// Sets the HandleKineticScrolling property. This dependency property
public static void SetHandleKineticScrolling(DependencyObject d, bool value)
d.SetValue(HandleKineticScrollingProperty, value);
/// Handles changes to the HandleKineticScrolling property.
private static void OnHandleKineticScrollingChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
ScrollViewer scoller = d as ScrollViewer;
if ((bool)e.NewValue)
scoller.MouseDown += OnMouseDown;
scoller.MouseMove += OnMouseMove;
scoller.MouseUp += OnMouseUp;
SetInertiaProcessor(scoller, new InertiaHandler(scoller));
else
scoller.MouseDown -= OnMouseDown;
scoller.MouseMove -= OnMouseMove;
scoller.MouseUp -= OnMouseUp;
var inertia = GetInertiaProcessor(scoller);
if (inertia != null)
inertia.Dispose();
#region Mouse Events
private static void OnMouseDown(object sender, MouseButtonEventArgs e)
var scrollViewer = (ScrollViewer)sender;
if (scrollViewer.IsMouseOver)
// Save starting point, used later when determining how much to scroll.
SetScrollStartPoint(scrollViewer, e.GetPosition(scrollViewer));
SetScrollStartOffset(scrollViewer, new
Point(scrollViewer.HorizontalOffset, scrollViewer.VerticalOffset));
scrollViewer.CaptureMouse();
private static void OnMouseMove(object sender, MouseEventArgs e)
if (scrollViewer.IsMouseCaptured)
Point currentPoint = e.GetPosition(scrollViewer);
var scrollStartPoint = GetScrollStartPoint(scrollViewer);
// Determine the new amount to scroll.
Point delta = new Point(scrollStartPoint.X - currentPoint.X,
scrollStartPoint.Y - currentPoint.Y);
var scrollStartOffset = GetScrollStartOffset(scrollViewer);
Point scrollTarget = new Point(scrollStartOffset.X + delta.X,
scrollStartOffset.Y + delta.Y);
var inertiaProcessor = GetInertiaProcessor(scrollViewer);
if (inertiaProcessor != null)
inertiaProcessor.ScrollTarget = scrollTarget;
// Scroll to the new position.
scrollViewer.ScrollToHorizontalOffset(scrollTarget.X);
scrollViewer.ScrollToVerticalOffset(scrollTarget.Y);
private static void OnMouseUp(object sender, MouseButtonEventArgs e)
scrollViewer.ReleaseMouseCapture();
#region Inertia Stuff
/// Handles the inertia
class InertiaHandler : IDisposable
private Point previousPoint;
private Vector velocity;
ScrollViewer scroller;
DispatcherTimer animationTimer;
private Point scrollTarget;
public Point ScrollTarget {
get { return scrollTarget; }
set { scrollTarget = value; } }
public InertiaHandler(ScrollViewer scroller)
this.scroller = scroller;
animationTimer = new DispatcherTimer();
animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 20);
animationTimer.Tick += new EventHandler(HandleWorldTimerTick);
animationTimer.Start();
private void HandleWorldTimerTick(object sender, EventArgs e)
if (scroller.IsMouseCaptured)
Point currentPoint = Mouse.GetPosition(scroller);
velocity = previousPoint - currentPoint;
previousPoint = currentPoint;
if (velocity.Length > 1)
scroller.ScrollToHorizontalOffset(ScrollTarget.X);
scroller.ScrollToVerticalOffset(ScrollTarget.Y);
scrollTarget.X += velocity.X;
scrollTarget.Y += velocity.Y;
velocity *= KineticBehaviour.GetFriction(scroller);
#region IDisposable Members
public void Dispose()
animationTimer.Stop();
<ScrollViewer x:Name="ScrollViewer" local:KineticBehaviour.HandleKineticScrolling="True" local:KineticBehaviour.Friction="1" >
I want to use XamDataGrid also in the same way.
<igDP:XamDataGrid BindToSampleData="True" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" local:KineticBehaviour.HandleKineticScrolling="True" ></igDP:XamDataGrid>
Can I do this?
Thanks,
Uday.
Hello Uday,
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking through your post and I suggest you use Utilities class which originates in the Infragistics.WPF4.dll file. You can use this code:
var sv = Utilities.GetDescendantFromType(xamDataGrid1,typeof(ScrollBar),true);
to get instance of the XamDataGrid’s ScrollBar.
Feel free to write me if you have further questions.