Search code examples
listviewwindows-store-appswindows-phone-8.1scrollviewerwin-universal-app

WP 8.1 Universal: Prevent ScrollViewer from automatically moving scrolled content to left edge


I have a ListView with images and I'd like to be able to zoom into the whole listview while still being able to scroll the listview. Therefore I put a ScrollViewer around the ListView.

Zooming with pinch to zoom works like it want it to, but the zoomed (or moved) position is not kept. Instead the content is automatically moving to left alignment after 300ms to 2sec.

How can I stop the ScrollViewer from automatically left aligning the content?

To reproduce just put the following as main content into WP-MainPage of new empty universal project, start, zoom in, move the zoomed content around (e. g. to the right side) and let it stay:

<ScrollViewer ZoomMode="Enabled" MinZoomFactor="1" MaxZoomFactor="4">

    <Image Source="http://upload.wikimedia.org/wikipedia/commons/c/ce/Motu_Maina.JPG"/>

</ScrollViewer>

(I removed the the ListView from inside the ScrollViewer for simplicity of the example.)


Solution

  • You have to specify the HorizontalScrollBarVisibility to Auto or Hidden because by default is disabled.

    <ScrollViewer ZoomMode="Enabled" HorizontalScrollBarVisibility="Auto">
        <Image x:Name="ImgFoto" Stretch="Uniform"></Image>
    </ScrollViewer>