private void _list_PreviewTouchMove(object sender, TouchEventArgs e)
{
FrameworkElement findSource = e.OriginalSource as FrameworkElement;
ListBoxItem element = null;
while (element == null && findSource != null)
if ((element = findSource as ListBoxItem) == null)
findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
if (element != null)
last_dragged_element = element;
this.touch_points.Add(e.GetTouchPoint(this._list as IInputElement));
if (touch_points.Count < configurations.min_touch_points) return;
double dy = touch_points[touch_points.Count - 1].Position.Y - touch_points[touch_points.Count - 2].Position.Y;
double dx = touch_points[touch_points.Count - 1].Position.X - touch_points[touch_points.Count - 2].Position.X;
double size_n = Math.Sqrt(dx * dx + dy * dy);
dx = dx / size_n; dy = dy / size_n;
if (dx == double.NaN || dy == double.NaN) return;
double theta1 = Math.Acos(dx * drag_direction1.X + dy * drag_direction1.Y);
double theta2 = Math.Acos(dx * drag_direction2.X + dy * drag_direction2.Y);
//convert to degree
theta1 = theta1 * 180 / Math.PI;
theta2 = theta2 * 180 / Math.PI;
double theta = (theta1 < theta2) ? theta1 : theta2;
if (theta < configurations.drag_collection_theta)
{
if (consecutive_drag_points < configurations.max_consecutive_drag_points)
{
consecutive_drag_points++;
}
else
{
if (is_tap.ContainsKey(e.TouchDevice.Id)) is_tap[e.TouchDevice.Id] = false;
if (element == null) element = last_dragged_element;
if (element != null)
{
avatar_drag(element, e.TouchDevice);
touch_points.Clear();
consecutive_drag_points = 0;
e.Handled = true;
return;
}
}
}
ScrollViewer scroll = configurations.GetDescendantByType(this._list, typeof(ScrollViewer)) as ScrollViewer;
double dv = touch_points[touch_points.Count - 1].Position.Y - touch_points[0].Position.Y;
dx = touch_points[touch_points.Count - 1].Position.X - touch_points[0].Position.X;
//double new_offset = scroll.HorizontalOffset + (-1 * configurations.scroll_scale_factor * dx);
if (dv > configurations.tap_error || dx > configurations.tap_error)
if (is_tap.ContainsKey(e.TouchDevice.Id)) is_tap[e.TouchDevice.Id] = false;
double new_offset = last_scroll_offset + (-1 * dv);
try { scroll.ScrollToVerticalOffset(new_offset); }
catch (Exception) { }
}