I’m trying to implement custom zoom on image in WinUI 3 using ScrollView
. Its standard zoom is working with pinching on touchpad but not on mouse wheel. So I decided to use PointerWheelChanged
to handle zoom using wheel but for this to work I needed to set VerticalScrollMode="Disabled"
. Now zoom on mouse wheel works fine but two finger scrolling with touchpad doesn’t work at all. It doesn’t fire PointerWheelChanged
and scrolling with it doesn’t work, because vertical scroll is disabled.
My goal is: I want to make touchpad actually scroll, since it already supports pinch zoom, it doesn’t need another one instead of scrolling.
I noticed that there’s PointerDeviceType
in event arguments, so I decided to test it in other events (like PointerMoved
) but, for some reason, it always has PointerDeviceType.Mouse
value, even when using touchpad. I read that I might need to use Manipulation events but after trying each of them, none seem to work at all.
<Grid Grid.Row="1">
<ScrollView ZoomMode="Enabled" MaxZoomFactor="4.0" MinZoomFactor="0.5" Name="MainScrollView"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
PointerWheelChanged="ScrollView_OnPointerWheelChanged"
VerticalScrollMode="Disabled" ContentOrientation="None">
<Grid>
<Image Name="Image" Source="" />
</Grid>
</ScrollView>
</Grid>
Here is the code-behind of the event. But as I said earlier: it doesn’t fire at all when I use touchpad.
private void ScrollView_OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType != PointerDeviceType.Mouse)
return;
var position = e.GetCurrentPoint(Image);
var factor = position.Properties.MouseWheelDelta > 0 ? 0.1f : -0.1f;
MainScrollView.ZoomBy(factor, new Vector2((float)position.Position.X, (float)position.Position.Y));
e.Handled = true;
}
RoseusFox is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.