I have a big image in the scrollviewer, so now I need to scale an image to see part of that image on the full screen. I need to do that from my code. How to do that?
Asked
Active
Viewed 1,217 times
1
-
See the http://stackoverflow.com/questions/16930074/wpf-image-pan-zoom-and-scroll-with-layers-on-a-canvas. Maybe help. – Anatoliy Nikolaev Jun 30 '13 at 06:10
-
It's either WPF or WinRT-XAML. Can't be both unless you are asking something fundamental to all XAML UI platforms. I'll assume you are asking about winrt-xaml though since it's a common misconception it is some new version of WPF. What is more relevant though is if it is for Windows 8.0 or Windows 8.1, since the answer might be different for these two. – Filip Skakun Jun 30 '13 at 07:58
1 Answers
3
In Windows 8.0 you would set the ZoomFactor
property on the ScrollViewer
to scale its content.
In Windows 8.1 the ScrollViewer
has a ChangeView()
method that takes parameters for zoom factor as well as horizontal and vertical offsets and supports view change animations.
To get it to fill your screen you would compare the ActualWidth
or ActualHeight
properties of your ScrollViewer
and its content and set the zoom factor to the result.

Filip Skakun
- 31,624
- 6
- 74
- 100
-
ChangeView is exactly what I need... Is there any solution for Windows 8.0? I understand that it's possible to use HorisontalOffset/VerticalOffset and ZoomFactor, but I can't figure out how... – Spinifex3 Jul 01 '13 at 11:16
-
Exactly what I said - `sv.ZoomFactor = Math.Max(sv.ActualWidth / content.ActualWidth, sv.ActualHeight / content.ActualHeight);` – Filip Skakun Jul 01 '13 at 15:23
-
Are you sure that in w8 property ScrollViewer.ZoomFactor has a setter? I think we can't set any value - [docs](http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.scrollviewer.zoomfactor) Maybe we should use [ZoomToFactor](http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.scrollviewer.zoomtofactor)? – jimpanzer Dec 10 '13 at 09:42
-