【问题标题】:DoubleTapped Event not working on WebViewDoubleTapped 事件在 WebView 上不起作用
【发布时间】:2014-05-31 22:54:33
【问题描述】:

我有一个工作正常的WebView 控件,但是当我尝试将 DoubleTapped 事件附加到控件时,当我实际继续并双击模拟器中的 Web 内容时,它似乎不起作用。有什么需要做的吗?

我的 XAML:

<Grid x:Name="LayoutRoot" DataContext="{StaticResource FeedEntryModel}">
    <WebView x:Name="feedEntry" IsHitTestVisible="True" DefaultBackgroundColor="WhiteSmoke"  DoubleTapped="feedEntry_DoubleTapped" IsDoubleTapEnabled="True" IsTapEnabled="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" IsHoldingEnabled="True" />
</Grid>

事件处理程序

private void feedEntry_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
    feedEntry.Navigate(new Uri("http://www.google.com"));
}

有什么想法吗?

【问题讨论】:

  • 尝试使用'ScriptNotify'并注入一些js来检测内部双击。使用'window.external.notify(obj);'通知您的外部代码。在这种情况下,obj 是一个 json,它将允许我通知多个事件。在您的情况下,您可以简单地添加“ondblclick”事件并调用该函数来通知您的代码。

标签: c# xaml webview event-handling windows-phone-8.1


【解决方案1】:
window.document.ondblclick = function() {
    window.external.notify("dblclick");
}

private void OnScriptNotify(object sender, NotifyEventArgs e)
{
    if (e.Value == "dblclick")
    {
    }
}

【讨论】:

    【解决方案2】:

    这是因为 WebView 内容获得了双击。试试这样的方法怎么样:

    <Grid x:Name="LayoutRoot">
        <WebView x:Name="feedEntry" Source="http://igrali.com" IsHitTestVisible="True" DefaultBackgroundColor="WhiteSmoke" IsDoubleTapEnabled="True" IsTapEnabled="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" IsHoldingEnabled="True" />
        <Grid DoubleTapped="feedEntry_DoubleTapped"
              Background="Transparent"/>
    </Grid>
    

    【讨论】:

    • 这使得双击工作但现在与 WebView 的交互已停止。我无法滚动或点击链接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 2011-10-08
    • 1970-01-01
    • 2023-03-08
    • 2021-02-18
    相关资源
    最近更新 更多