简体   繁体   中英

Xamarin Forms Pinch to zoom event not raised

I've been trying to implement a page with a WebView and do some custom code in pinch to zoom. But the event "PinchUpdated" of the "PinchGestureRecognizer" will not be raised.

Page:

<ContentPage.Content>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <WebView Grid.Column="0" Grid.Row="0" Source="https://google.com/" />
    </Grid>
</ContentPage.Content>

Code:

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyPage : ContentPage
{
    private PinchGestureRecognizer pinchRecognizer = new PinchGestureRecognizer();

    public MyPage()
    {
        InitializeComponent();

        this.pinchRecognizer.PinchUpdated += this.HandlePinchUpdated;
    }

    private void HandlePinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
    {
        // Do something
    }
}

When I set a break point in the event it will not be hit. Not in emulator or on a real device.

Any suggestions?

By what you're saying, I think you're problem is in how events are handled against webviews. By default if you try to pinch zoom inside the frame of the webview, it will only affect the html in the webview. If you are not intending on interacting with the webview, try placing a mask (BoxView) over the top of the whole Webview, and then apply the pinch zoom to the mask box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM