Unanswered scrollviewer - zooming issue

  • Tuesday, July 10, 2012 2:54 PM
     
     

    Hello,

    I'd like to submit you a problem I'm encountering with my scrollviewer. It is filled with 70 items. I move to the middle of the scroll, and I zoom in, and I log 3 properties of the scrollviewer during the viewChanged events. I have set the max zoom to 1. Here is what I get:

    Some définitions:

    zoom = ZoomFactor

    eWidth = ExtentWidth

    hOffset = HorizontalOffset

    ratio = hOffset / eWidth

    The log (look at the zoom and the ratio):

    zoom    0.505961
    eWidth  75118.195313
    hOffset 36922.503906
    ratio 0.491525

    zoom    0.505961
    eWidth  81853.390625
    hOffset 40287.609375
    ratio 0.492192

    zoom    0.797718
    eWidth  81853.390625
    hOffset 40287.609375
    ratio 0.492192

    zoom    0.797718
    eWidth  129053.195313
    hOffset 63863.578125
    ratio 0.494862

    zoom    1.000000
    eWidth  129053.195313
    hOffset 63863.578125
    ratio 0.494862

    zoom    1.000000
    eWidth  161778.000000
    hOffset 88715.187500
    ratio 0.548376            <---- JUMP

    zoom    1.000000
    eWidth  161778.000000
    hOffset 80238.000000
    ratio 0.495976

    zoom    1.000000
    eWidth  161778.000000
    hOffset 80238.000000
    ratio 0.495976

    When the ratio jumps from 0.49 to 0.54, the zoom stays to 1. This is not a negligible change because I have a lot of items, this is equivalent to moving 3 pages to the right ! I pinch the screen in a way that the item stays on the screen, thus the crazy value 0.53 should stay near 0.49, and this is very annoying because I need to know at which item I am.

    Is there a reason to this behavior ?

    Thank you

All Replies

  • Tuesday, July 10, 2012 11:58 PM
    Moderator
     
     

    Can you please explain what your code is doing more clearly? It would help if you can provide minimal code to reproduce the problem, exact repro steps, the behavior you expect, and the actual behavior you get.

    --Rob

  • Wednesday, July 11, 2012 7:18 AM
     
     

    Thank you for your answer.

    My code is doing nothing, I have 70 images in a stackpanel in a scrollviewer. I zoom in the 40th image, and I just look at the values of the scrollviewer each time I get a viewChanged event. I just want to know if this is a normal behaviour. If so, I need to know which values I can use to know exactly my ratio position (in the ranges 0 to 1) in the stack. What I expect is a quasi constant ratio because I'm just zooming and not moving in the stack.

    You can also see in the log, that the zoom is not synchronized with the other values : for 2 constant zoom values, the ExtentWidth and HorizontalOffset can change.

    This is totally confusing, I need coherent values

  • Friday, August 03, 2012 8:17 AM
     
     

    I still need to fix this problem.

    Cheers

  • Friday, August 03, 2012 8:21 PM
    Moderator
     
     

    Can you please provide minimal code to reproduce the problem, exact repro steps, the behavior you expect, and the actual behavior you get?

    --Rob

  • Tuesday, August 07, 2012 9:02 AM
     
      Has Code

    You can use the xaml scrolling, panning, and zooming c# sample available here:

    http://code.msdn.microsoft.com/windowsapps/XAML-ScrollViewer-pan-and-949d29e9

    You'll need to add a few lines of code.

    In the Scenario2.cs

    0) add

    using System.Diagnostics;

    1) add the method

    private void onViewChanged(Object window, ScrollViewerViewChangedEventArgs args){
    
    Debug.WriteLine(scrollViewer.ZoomFactor + " " + scrollViewer.ExtentWidth + " " + scrollViewer.HorizontalOffset);
    
    }

    2) in the OnNavigatedTo, add

    scrollViewer.ViewChanged += onViewChanged;

    3) in the Scenario2.xaml, replace ZoomMode="Disable" with

    ZoomMode="Enabled" MinZoomFactor=".4" MaxZoomFactor="1"

    Now run the sample, select the scenario2 and scroll a little in the stackpanel. Zoom in. You may know that the MaxZoomFactor isn't really a maximum: you can zoom farther than the maxZoomFactor, but when you release the pointers, an animation zoom back to the MaxZoomFactor. This is when we are zooming farther than the maxZoomFactor that things are getting interesting:

    You will see that the zoom stays constant to 1, the extentWidth stays constant to 2340, and the horizontalOffset continues growing.

    The horizontalOffset grows ? This is ok because the left part of the stack is larger when zooming. But if the horizontalOffset grows, so should the extentWidth.

    This is a big problem as I need these two values for calculation.

    Of course the issue is the same below the MinZoomFactor.

    Please help

    Cheers


  • Monday, August 20, 2012 7:40 AM
     
     

    Please tell me if I lost you somehow.

    Cheers

  • Thursday, August 30, 2012 8:58 AM
     
     

    Hello,

    Did you try the sample ?

    This is a very minimal sample, with 4 lines to paste, that readily highlights the problem.

    Hoping some news

    Cheers

  • Thursday, August 30, 2012 4:56 PM
    Moderator
     
     

    I can reproduce the behavior you describe:

    the zoom stays constant to 1, the extentWidth stays constant to 2340, and the horizontalOffset continues growing.

    The following statement conclusion appears incorrect

    if the horizontalOffset grows, so should the extentWidth.

    The ExtentWidth isn't dependent on the HorizontalOffset. The ExtentWidth is the width of the entire content, visible or not. This isn't affected by scrolling. The HorizontalOffset determines which part of that content is visible, but doesn't affect the actual width.

    --Rob

  • Monday, September 03, 2012 8:58 AM
     
     

    Thank you for your answer.

    I understand that the ExtentWidth is not affected by scrolling. What I try to explain is that it is affected by zooming. Zooming increases the ExtentWidth, and zooming increases the HorizontalOffset. I made a shortcut for readability. This behaviour should not change past a certain level of zooming, or there is no way to determine the true HorizontalOffset ratio. Let's take an example:

    I'm at HorizontalOffset = 500 and ExtentWidth = 1000;

    I can say I'm at half the document : 500/1000 = .5

    I zoom, HorizontalOffset = 1000 and ExtentWidth = 2000;

    I can say I'm at half the document : 1000/2000 = .5

    I zoom further, HorizontalOffset = 1500 and ExtentWidth = 2000;

    Can I say that I'm at half the document ? no because : 1500/2000 != .5, because these two values are not constistant past a certain level of zoom.

  • Friday, September 21, 2012 9:45 AM
     
     

    Any news ?

    Cheers