Search code examples
c#avaloniauiavalonia

How to disable scrolling in ScrollViewer in AvaloniaUI?


I am using MapControl(MapsUI) in ScrollViewer in my AvaloniaUI 11.0.5. app. I need to disable scrolling in ScrollViewer while pointer is in MapControll. I have tried this code but it did not work:

AXAML:

<ScrollViewer Name="mainPanel">
...
<Panel PointerEntered="disableScroll" PointerExited="enableScroll" Name="MapBox" /> //here is MapControl added later in code
...
///some very big stuff here like Panels, TextBoxes, Images etc.
...
</ScrollViewer>

c#:

private void disableScroll(object o, PointerEventArgs e)
{
    mainPanel.VerticalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled;
}

private void enableScroll(object o, PointerEventArgs e)
{
    mainPanel.VerticalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Auto;
}

Maybe is there some pre-scroll event? Any ideas please?


Solution

  • After very long time I found a solution.

    I created function:

    private void MapControl_PointerWheelChanged(object sender, PointerWheelEventArgs e)
    {
        e.Handled = true;
    }
    

    and and assigned it to MapControl in axaml:

    <avalonia:MapControl Name="Map" PointerWheelChanged="MapControl_PointerWheelChanged"/>
    

    Now I can zoom in and out the Map without scrolling the ScrollViewer at the same time.