Windows应用程序ScrollViewer.ChangeView()不工作

本文关键字:工作 ChangeView 应用程序 ScrollViewer Windows | 更新日期: 2023-09-27 17:51:03

尝试在双击事件触发的windows store应用程序中缩小滚动视图

这是应该发生的代码

private void MainPhotoDisplay_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
    MainPhotoDisplayscrollViewer.ChangeView(null, null, 1.0F,true);
}

但是如果我放大,在模拟器中,然后双击,什么都没有发生。事件触发,方法运行,但是什么也没发生,视图保持在缩放状态。

这里是它的文档:http://msdn.microsoft.com/en-us/library/windows/apps/dn252762.aspx

这个过时的方法:

 MainPhotoDisplayscrollViewer.ZoomToFactor(1);

工作得很好,但遗憾的是它没有动画,这使得糟糕的用户体验。这不是我真正想要的。

你知道为什么什么都没发生吗?

Windows应用程序ScrollViewer.ChangeView()不工作

另一种解决方案是在指令之前添加Task.Delay调用。

很奇怪,但是很管用。

await Task.Delay(1);
scroller.ChangeView(null, null, null, false); // whatever

解决方案:http://social.msdn.microsoft.com/forums/windowsapps/en - us/c3eac347 fe08 - 41 - bd - 98 - cb - d97b6f260873/double -利用-放大-图像- windows - 81 scrollviewerchangeview?forum=winappswithcsharp

在这里标记为解决方案的帖子实际上是有效的,但是,如果您在有问题的scrollViewer的页面的代码后面运行代码,则不需要事件的前3行。请记住将调用中的最后一个bool值设置为false以显示动画。

var period = TimeSpan.FromMilliseconds(10);
        Windows.System.Threading.ThreadPoolTimer.CreateTimer(async (source) =>
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                var Succes = MainPhotoDisplayscrollViewer.ChangeView(null, null, 1.0F, false);
            });
        }, period);