4,153 questions
In .NET MAUI, how can I implement zooming and scrolling functionality in a GraphicsView element?

S GAIKWAD
231
Reputation points
Dot NET version - 7
Platform - Android or iOS
Vishal studio - latest updated
///Xaml code
<ScrollView Orientation="both">
<GraphicsView x:Name="graphicsView">
<GraphicsView.GestureRecognizers>
<PanGestureRecognizer PanUpdated="OnPanUpdated" />
<PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
</GraphicsView.GestureRecognizers>
</GraphicsView>
</ScrollView>
///Code behind
private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
{
switch (e.Status)
{
case GestureStatus.Started:
// Store the current scale factor applied to the wrapped user interface element,
// and zero the components for the center point of the translate transform.
startScale = graphicsView.Scale;
graphicsView.AnchorX = e.ScaleOrigin.X;
graphicsView.AnchorY = e.ScaleOrigin.Y;
break;
case GestureStatus.Running:
// Calculate the scale factor to be applied.
currentScale += (e.Scale - 1) * startScale;
currentScale = Math.Max(1, currentScale);
graphicsView.Scale = currentScale;
break;
case GestureStatus.Completed:
// Store the final scale factor applied to the wrapped user interface element.
startScale = currentScale;
break;
}
}
private void OnPanUpdated(object sender, PanUpdatedEventArgs e)
{
graphicsView.TranslationX += e.TotalX;
graphicsView.TranslationY += e.TotalY;
}
I am drawing lines in graphicsView.
Zoom in and zoom out functionality it's working properly but getting issue when user zoom in graphicsView and he try scroll up, down left and right. Scroll doesn't work.
So, I want to scroll zoom in part any direction like vertical or horizontal.
Developer technologies | .NET | .NET MAUI
Sign in to answer