Windows 8 使用鼠标滚动Win 8.1 Metro Hub导航

Windows 8 使用鼠标滚动Win 8.1 Metro Hub导航,windows-8,windows-store-apps,scrollview,winrt-xaml,horizontaloffset,Windows 8,Windows Store Apps,Scrollview,Winrt Xaml,Horizontaloffset,我试图找到一个解决方案,当鼠标到达左边界或右边界时,允许中心用鼠标平移。我已经实现了下面我从各种来源收集的代码 ` private void theHubPointerMoved(object sender, PointerRoutedEventArgs e) { Windows.UI.Xaml.Input.Pointer ptr = e.Pointer; if (ptr.PointerDeviceType == Windows.Devices.Input.Pointe

我试图找到一个解决方案,当鼠标到达左边界或右边界时,允许中心用鼠标平移。我已经实现了下面我从各种来源收集的代码

` 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;
    }`
`private void thehubbointermoved(对象发送方,pointErrorouted事件参数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);
如果(ptrPt.Position.X20)
{
//在这里进行滚动
var xcord=数学圆(ptrPt.Position.X,2);
var ycord=数学圆(位置Y,2);
}
}
e、 已处理=正确;
}`
因此,当鼠标位于屏幕边缘时,相对容易看到。我认为简单地使用MyHub.ScrollViewer.ScrollToHorizontalOffset(xcord)是很容易的但是Hub Scrollviewer没有公开这个ScrollToHorizontalOffset函数

有人能帮忙吗


谢谢。

哦,它暴露了。如果你能帮我挖的话。以下是方法:

在下面的示例中,它滚动到特定的中心部分。但我希望你能很容易地适应你的特殊需要

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);
}
private void ScollHubToSection(轮毂、轮毂部分)
{
var visual=section.TransformToVisual(this.MyHub);
var point=visual.TransformPoint(新点(0,0));
var viewer=Helpers.FindChild(hub,“ScrollViewer”);
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;
    }
}
公共类助手
{
公共静态T FindChild(DependencyObject父对象,字符串childName),其中T:DependencyObject
{
if(parent==null)返回null;
T foundChild=null;
int childrenCount=visualtreeheloper.GetChildrenCount(父级);
for(int i=0;i

祝你好运

谢谢Jerry会查出来的Jerry你就是那个人!几天来我一直在努力解决这个问题。这是一种享受。