Xaml WebView手势识别在Xamarin表单中不起作用

Xaml WebView手势识别在Xamarin表单中不起作用,xaml,xamarin.forms,Xaml,Xamarin.forms,我有一个网络视图点击此网络视图时,我需要使按钮可见问题是手势识别不起作用 我的Xaml <customRenderer:CustomWebView Uri="{Binding SelectedJournal.Uri}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" x:Name="CustomWebView" AbsoluteLayout.LayoutBounds="0,50,1,1" Absol

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

我的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" >
这应该行得通,但这行不通

也是我的自定义渲染web视图类

  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); }
    }
}
公共类CustomWebView:WebView
{
公共静态只读BindableProperty UriProperty=BindableProperty.Create(p=>p.Uri,默认值(字符串));
公共字符串Uri
{
获取{return(string)GetValue(UriProperty);}
set{SetValue(UriProperty,value);}
}
}

如何实现这一点

您可以使用视图的“聚焦”事件来显示按钮,而不是在webview上使用手势识别器。您可以这样做:

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()。

您为什么要这样做?@G.hakim我有一个按钮我使用这个webview在触摸内容时显示pdf我需要弹出一个按钮这是我的目的好的一个!谢谢你。
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();
 };