Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WebBrowser控件中,window.external不可用_C#_Silverlight_Windows Phone 7_Webbrowser Control - Fatal编程技术网

C# 在WebBrowser控件中,window.external不可用

C# 在WebBrowser控件中,window.external不可用,c#,silverlight,windows-phone-7,webbrowser-control,C#,Silverlight,Windows Phone 7,Webbrowser Control,我想在WebBrowser控件中调用C#方法。下面是我的代码: 在XAML中 <phone:WebBrowser Margin="0,0,0,0" Name="WebBrowserForDetails" VerticalAlignment="Top" Height="300" ScriptNotify="WebBrowserForDetails_ScriptNotify" IsScriptEnabled="True" /> 在C#中 受保护的覆盖无效OnNavigatedTo(

我想在WebBrowser控件中调用C#方法。下面是我的代码:

在XAML中

<phone:WebBrowser Margin="0,0,0,0" Name="WebBrowserForDetails" VerticalAlignment="Top" Height="300" ScriptNotify="WebBrowserForDetails_ScriptNotify" IsScriptEnabled="True" />

在C#中

受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
stringhtml=string.Format(“{0}Push”,“函数调用(){window.external.notify(123);}”);
WebBrowserForDetails.NavigateToString(html);
}
私有void WebBrowserForDetails_ScriptNotify(对象发送方,NotifyEventArgs e)
{
Debug.WriteLine(e.Value);
}
应在调试窗口中看到
123

当按下
Push
时,
window.external.notify
永远不会被调用。实际上,
window.external
不可用。我想从WebBrowser控件调用
window.external.notify
函数来调用
WebBrowserForDetails\u ScriptNotify
方法。我该怎么办

编辑


参考链接:,和

我怀疑您的问题是由于未提供有效的HTML5文档,因为您的(正文和html)元素未关闭。

首先,您可能想阅读Mike Taulty对脱机浏览器内容的评论


您的代码似乎是正确的,但window.external.notify()方法采用的是字符串参数,而不是整数。请改用window.external.notify('123')调用。
希望这有帮助。

我想你是说Windows-Phone-7吧?不是Windows Mobile。作为将来的参考,我们希望stackoverflow问题的内容实际上包含一个问题。你说的是事实陈述。@AnthonyWJones是的,我说的是WP7。我还把这个问题编辑成了一个问题。谢谢你的评论:)+1作为最后一点,但是你需要更仔细地阅读问题中的代码,你的前两点都不正确。它不是HTML5文档。我没有声明doctype:
。根据HTML4规范(以及HTML5规范),您不需要结束正文和html标记。虽然我放置了结束标记,但我仍然
窗口。外部
给出一个空值:(问题是
window.external
只返回空值,所以我甚至无法进入
window.external.notify
有一个适合我的测试项目:文件不再可用…请提供代码或新链接!抱歉,没有此项目的副本。主题项目之间的主要区别是将一个数字作为s传递。)字符串-->“123”
protected override void OnNavigatedTo(NavigationEventArgs e)
{

    string html = string.Format("<html><head><title></title><script type=\"text/javascript\">{0}</script></head><body><button onclick=\"call();\">Push</button>", "function call(){ window.external.notify(123) ;}");
    WebBrowserForDetails.NavigateToString(html);
}

private void WebBrowserForDetails_ScriptNotify(Object sender, NotifyEventArgs e)
{
    Debug.WriteLine(e.Value);
}