Asked by:
Resizing the content of a ScrollViewer

Question
-
Hi all,
I've got a program in which I want to display rendered content inside a Scrollviewer that allows zoom. What I do when the user zooms is that I resize the content of the ScrollViewer and then I want to change the view position and zoom factor so that it looks like I'm at the same position as I just was. Basically, I want the zoom factor to always be 1 (except during zoom, since the system takes care of that).
So, I created a small sample where I have a ScrollViewer (mMainScroller) and a Canvas (mMainCanvas) as the content of the ScrollViewer. So, when the ScrollViewer finishes it's manipulation, I want to resize the canvas and then set the zoom factor back to 1 (the reason is that I'm using rendered content, so when you zoom in I want to re-render at this larger scale and then replace the content). The reason I do it this way is because the zoom limits of the ScrollViewer isn't large enough for my app, and also I found that when using really high zoom levels, it doesn't work smoothly anymore (http://social.msdn.microsoft.com/Forums/windowsapps/en-US/d9d3f1b6-89cb-4b15-a891-5c98fafe5bc9/scrollviewer-jumps-around-on-high-zoom-levels#d9d3f1b6-89cb-4b15-a891-5c98fafe5bc9).
Either way, here's the code I've added to mMainScroller's viewChanedHandler:
private void ViewChangedHandler(object sender, ScrollViewerViewChangedEventArgs e) { if (e.IsIntermediate) { System.Diagnostics.Debug.WriteLine("intermediate"); } else { System.Diagnostics.Debug.WriteLine("Finished"); double zoomValue = mMainScroller.ZoomFactor; double newWidth = mMainCanvas.Width * zoomValue; double newHeight = mMainCanvas.Height * zoomValue; double newXPos = mMainScroller.HorizontalOffset; double newYPos = mMainScroller.VerticalOffset; mMainCanvas.Width = newWidth; mMainCanvas.Height = newHeight; mMainScroller.ChangeView(newXPos, newYPos, 1, true); } }
mMainCanvas is basically just a 5000 x 5000 canvas.
I hope that gives you an idea of what I am trying to accomplish. I find that it "almost" works. However, there is a jump by the scroll bar, and with content that was more varied in it's appearance, you might see the content of the scroll viewer "flash" whatever's at that other position.
I will note that this is the same approach as I've used on Windows 8.0, but when trying to post it I am trying to use the new ChangeView function as opposed to ScrollToVerticalOffset and so on, which are all deprecated.
I would really appreciate some suggestions.
Thanks,
Tomas Hofmann
- Moved by Ryan BolzMicrosoft employee Thursday, October 17, 2013 7:11 PM support request per 8.1 launch
Tuesday, October 1, 2013 7:22 PM
All replies
-
Hi Tomas,
Is this thread based on what you saw in your previous thread? If so, can you check whether the recommendation I suggested on the other thread applies to you? If not, I will take a look at this thread and we can investigate further.
Thanks,
Prashant.
Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz
Wednesday, October 2, 2013 1:46 AMModerator -
Hi Prashant,
I would still very much appreciate some help with this. The other option was something I was considering to use as a backup solution, and now it might be more viable. However, if we can solve this it would be better for me. This way, I don't have to re-implement anything.
Currently, I just left it with the old deprecated functions, and it's working fine, so I will just continue with that for now. Still, an upgrade to use the new function would be good to have.
So, I would appreciate if you could look into this.
Thanks for your help,
Tomas Hofmann
Thursday, October 3, 2013 11:01 PM