xaml - WebView GestureRecognition 在 Xamarin 表单中不起作用

标签 xaml xamarin.forms

我有一个网页 View ,当点击此网页 View 时,我需要使按钮可见,问题是手势识别不起作用

我的Xaml

   <customRenderer:CustomWebView Uri="{Binding SelectedJournal.Uri}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"  x:Name="CustomWebView" AbsoluteLayout.LayoutBounds="0,50,1,1" AbsoluteLayout.LayoutFlags="SizeProportional"  >
            <customRenderer:CustomWebView.GestureRecognizers>
                <TapGestureRecognizer Tapped="TapGestureRecognizer_OnTapped2" NumberOfTapsRequired="1" ></TapGestureRecognizer>
            </customRenderer:CustomWebView.GestureRecognizers>
        </customRenderer:CustomWebView>

        <customRenderer:NavigationImageButton ItemTapped="FullScreenOnTapped" Source="full.jpg" AbsoluteLayout.LayoutBounds="0.5,1,-1,-1" AbsoluteLayout.LayoutFlags="PositionProportional"  HeightRequest="60" WidthRequest="60" x:Name="FullScreenBtn" IsVisible="False" >

在后面的代码中我这样调用

private void TapGestureRecognizer_OnTapped2(object sender, EventArgs e)
    {
        FullScreenBtn.IsVisible = true;
    }

这应该有效,但不起作用

也是我的自定义渲染 Web View 类

  public class CustomWebView : WebView
{
    public static readonly BindableProperty UriProperty = BindableProperty.Create<CustomWebView, string>(p => p.Uri, default(string));

    public string Uri
    {
        get { return (string)GetValue(UriProperty); }
        set { SetValue(UriProperty, value); }
    }
}

如何实现这一目标

最佳答案

您可以使用 View 的“Focused”事件来显示按钮,而不是在 Web View 上使用手势识别器。你可以这样做:

var wb = new WebView
{
    HorizontalOptions = LayoutOptions.FillAndExpand,
    VerticalOptions = LayoutOptions.FillAndExpand,
    Source = "https://stackoverflow.com/questions/56320611/webview-gesturerecognition-not-working-in-xamarin-forms",
};

wb.Focused += (s, e) =>
{
   //Handle your logic here!
   wb.Unfocus();
 };

如果您希望每次点击 webview 时都实现逻辑,则可以使用 Unfocus()。

关于xaml - WebView GestureRecognition 在 Xamarin 表单中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56320611/

相关文章:

c# - XAML WPF 多边形(三角形),仅在 2/3 边上有边框

c# - Android 不支持全局 PushAsync,请使用 NavigationPage

ios - 如何使用 Xamarin 表单获取 iOS 的设备序列号

c# - 将样式中的 Setter 值绑定(bind)到主模型

c# - 自定义 NavigationView 面板以包含图像 UWP

windows - 在 XAML/WinRT 中本地化附加属性

wpf - 如何将子文件夹中定义的 ResourceDictionary 添加到 App.xaml?

xamarin - 在 xamarin Forms 中绑定(bind) listView 的 Itemsource 外部的数据

xamarin - 在 Xamarin.Forms 中实现回收单元格网格的最佳方法?

xamarin.forms - 未找到 Xaml 标记扩展