0

我正在尝试找到一种解决方案,以允许集线器在到达左边界或右边界时用鼠标平移。我已经实现了我从各种来源收集到的下面的代码。

` private void theHubPointerMoved(object sender, PointerRoutedEventArgs e)
    { Windows.UI.Xaml.Input.Pointer ptr = e.Pointer;

        if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
        {
            Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint(null);
              if (ptrPt.Position.X < this.ActualWidth - 20)
                if (ptrPt.Position.X > 20)
                {
                    //Do the SCROLLING HERE
                    var xcord = Math.Round(ptrPt.Position.X, 2);
                    var ycord = Math.Round(ptrPt.Position.Y, 2);
                }
        }
           e.Handled = true;
    }`

所以当鼠标在屏幕边缘时很容易看到。我认为简单地使用MyHub.ScrollViewer.ScrollToHorizo​​ntalOffset(xcord);会很容易。但是 Hub Scrollviewer 没有公开这个 ScrollToHorizo​​ntalOffset 函数。

有人可以帮忙吗?

谢谢。

4

1 回答 1

0

哦,暴露了。如果你能处理挖掘它。就是这样:

http://xaml.codeplex.com/SourceControl/latest#Blog/201401-ScrollHub/MainPage.xaml.cs

在下面的示例中,它滚动到特定的中心部分。但我希望,您应该能够轻松地使其适应您的特定需求。

private void ScollHubToSection(Hub hub, HubSection section)
{
    var visual = section.TransformToVisual(this.MyHub);
    var point = visual.TransformPoint(new Point(0, 0));
    var viewer = Helpers.FindChild<ScrollViewer>(hub, "ScrollViewer");
    viewer.ChangeView(point.X, null, null);
}

使用这个:

public class Helpers
{
    public static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject
    {
        if (parent == null) return null;
        T foundChild = null;
        int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
        for (int i = 0; i < childrenCount; i++)
        {
            var child = VisualTreeHelper.GetChild(parent, i);
            T childType = child as T;
            if (childType == null)
            {
                foundChild = FindChild<T>(child, childName);
                if (foundChild != null) break;
            }
            else if (!string.IsNullOrEmpty(childName))
            {
                var frameworkElement = child as FrameworkElement;
                if (frameworkElement != null && frameworkElement.Name == childName)
                {
                    foundChild = (T)child;
                    break;
                }
            }
            else
            {
                foundChild = (T)child;
                break;
            }
        }
        return foundChild;
    }
}

祝你好运!

于 2014-01-03T17:45:12.490 回答