WPF WebBrowser中的LoadCompleted事件不起作用

时间:2014-06-26 05:13:57

标签: c# wpf webbrowser-control

我有一个WPF WebBrowser控件。

<WebBrowser Name="wbMap"></WebBrowser>

在后面的代码中,我在构造函数中调用一个函数,我在其中设置导航路径并在LoadCompleted事件中调用脚本。

private void LoadMap()
{
    if (DesignerProperties.GetIsInDesignMode(this)) return;
    //Get the application execution path
    String appdir = System.IO.Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
    //Combine the application execution path with map file name
    String mapPath = System.IO.Path.Combine(appdir, "MAP.html");
    //Navigate the browser to the above path
    wbMap.Navigate(mapPath);
    wbMap.LoadCompleted += wbMap_LoadCompleted;         
}

void wbMap_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    wbMap.InvokeScript("setLocation", "red");
}

此javascript函数在Google地图上设置默认位置。但是当我在LoadCompleted事件中调用它时,我看不到标记。然而,当我在Button.Click事件中添加一个按钮并添加它时,该位置正在设置。我该如何调用此功能?

0 个答案:

没有答案
相关问题