Question

Trying to make a scrollview zoom out in a windows store app triggered by the double tapped event.

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

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?

Was it helpful?

Solution 2

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

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. remember to set the last bool in the call to false to show the animation.

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);

OTHER TIPS

Another solution is to add a Task.Delay call before the instruction.

Really weird but it works.

await Task.Delay(1);
scroller.ChangeView(null, null, null, false); // whatever
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top