简体   繁体   English

Windows商店应用ScrollViewer.ChangeView()无法正常工作

[英]Windows store app ScrollViewer.ChangeView() not working

Trying to make a scrollview zoom out in a windows store app triggered by the double tapped event. 尝试在双击事件触发的Windows应用商店应用中缩小滚动视图。

this is the code where it's supposed to happen 这是它应该发生的代码

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

but if I zoom in, in the simulator and then double tap, nothing happens. 但如果我放大,在模拟器中,然后双击,没有任何反应。 the event does fire and the method is run but nothing happens, the view remains in the zoomed in state. 事件触发并且方法运行但没有任何反应,视图仍然处于放大状态。

here is the documentation for it: http://msdn.microsoft.com/en-us/library/windows/apps/dn252762.aspx 这是它的文档: http//msdn.microsoft.com/en-us/library/windows/apps/dn252762.aspx

this obsolete method: 这个过时的方法:

 MainPhotoDisplayscrollViewer.ZoomToFactor(1);

works just fine, but sadly it has no animation which makes for a bad user experience. 工作得很好,但遗憾的是它没有动画,这会导致糟糕的用户体验。 And is not really what I want. 并不是我想要的。

any ideas as to why nothing happens? 关于为什么没有发生的任何想法?

Another solution is to add a Task.Delay call before the instruction. 另一种解决方案是在指令之前添加Task.Delay调用。

Really weird but it works. 真的很奇怪,但它的确有效。

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

Solution found: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/c3eac347-fe08-41bd-98cb-d97b6f260873/double-tap-to-zoom-image-windows-81-scrollviewerchangeview?forum=winappswithcsharp 找到解决方案: http//social.msdn.microsoft.com/Forums/windowsapps/en-US/c3eac347-fe08-41bd-98cb-d97b6f260873/double-tap-to-zoom-image-windows-81-scrollviewerchangeview?forum = winappswithcsharp

the post marked as solution here actually works, however you don't need the first 3 lines of the event if you run the code inside the codebehind of the page with the scrollViewer in question. 这里标记为解决方案的帖子实际上是有效的,但如果您使用有问题的scrollViewer在页面的代码隐藏中运行代码,则不需要事件的前3行。 remember to set the last bool in the call to false to show the animation. 记得将调用中的最后一个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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM