Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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# wpf webbrowser控件和谷歌地图,覆盖灰色图像_C#_Wpf_Webbrowser Control - Fatal编程技术网

C# wpf webbrowser控件和谷歌地图,覆盖灰色图像

C# wpf webbrowser控件和谷歌地图,覆盖灰色图像,c#,wpf,webbrowser-control,C#,Wpf,Webbrowser Control,很长一段时间以来,我一直在使用c语言中的webbrowser控件来渲染google地图。最近,谷歌地图现在加载,然后覆盖一个灰色框。看到图片了吗 有人知道这是什么原因吗 this.webBrowser1.DocumentText = @"<iframe width=""425"" height=""350"" frameborder=""0"" scrolling=""no"" marginheight=""0"" marginwidth=""0"" src=""https://maps.

很长一段时间以来,我一直在使用c语言中的webbrowser控件来渲染google地图。最近,谷歌地图现在加载,然后覆盖一个灰色框。看到图片了吗

有人知道这是什么原因吗

this.webBrowser1.DocumentText = @"<iframe width=""425"" height=""350"" frameborder=""0"" scrolling=""no"" marginheight=""0"" marginwidth=""0"" src=""https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed""></iframe><br /><small><a href=""https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7"" style=""color:#0000FF;text-align:left"">View Larger Map</a></small>";
这个比率是正确的。我跟随他的链接,实现了项目的代码,它不再有这种行为

amespace WebBroweer控件 { 公开课表格1 { System.Windows.Forms.WebBrowser webBrowser1=null

    public Form1(System.Windows.Forms.WebBrowser br)
    {

        webBrowser1 = br;

        SetBrowserFeatureControl();



    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //DoNavigationAsync().ContinueWith(_ =>
        //{
        //    MessageBox.Show("Navigation complete!");
        //}, TaskScheduler.FromCurrentSynchronizationContext());


        //var html = "<iframe width=\"425\" height=\"350\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" " +
        //       "src=\"https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;" +
        //       "geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471," +
        //       "-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed\">" +
        //       "</iframe>" +
        //       "<br /><small><a href=\"https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas" +
        //       "&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;" +
        //       "sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7\" style=\"color:#0000FF;" +
        //       "text-align:left\">View Larger Map</a></small>";

        webBrowser1.Navigate("http://www.condoresorts.com/Directions/PrintShares/Coyote%20Lakes/Pillars%20to%20Coyote%20Lakes.htm");
    }

    private async Task DoNavigationAsync()
    {
        TaskCompletionSource<bool> documentCompleteTcs = null;

        WebBrowserDocumentCompletedEventHandler handler = delegate
        {
            if (documentCompleteTcs.Task.IsCompleted)
                return;
            documentCompleteTcs.SetResult(true);
        };

        documentCompleteTcs = new TaskCompletionSource<bool>();
        this.webBrowser1.DocumentCompleted += handler;

        // could do this.wb.Navigate(url) here 
        this.webBrowser1.DocumentText = "<!DOCTYPE html><head><meta http-equiv='X-UA-Compatible' content='IE=edge'/></head>" +
            "<body><input size=50 type='text' placeholder='HTML5 if this placeholder is visible'/></body>";

        await documentCompleteTcs.Task;
        this.webBrowser1.DocumentCompleted -= handler;

        dynamic document = this.webBrowser1.Document.DomDocument;
        dynamic navigator = document.parentWindow.navigator;
        var info =
            "\n navigator.userAgent: " + navigator.userAgent +
            "\n navigator.appName: " + navigator.appName +
            "\n document.documentMode: " + document.documentMode +
            "\n document.compatMode: " + document.compatMode;

        MessageBox.Show(info);
    }

    private static void SetBrowserFeatureControl()
    {
        // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

        // WebBrowser Feature Control settings are per-process
        var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);

        // make the control is not running inside Visual Studio Designer
        if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0)
            return;

        SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode());
    }

    private static void SetBrowserFeatureControlKey(string feature, string appName, uint value)
    {
        using (var key = Registry.CurrentUser.CreateSubKey(
            String.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature),
            RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
            key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord);
        }
    }

    private static UInt32 GetBrowserEmulationMode()
    {
        int browserVersion = 7;
        using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer",
            RegistryKeyPermissionCheck.ReadSubTree,
            System.Security.AccessControl.RegistryRights.QueryValues))
        {
            var version = ieKey.GetValue("svcVersion");
            if (null == version)
            {
                version = ieKey.GetValue("Version");
                if (null == version)
                    throw new ApplicationException("Microsoft Internet Explorer is required!");
            }
            int.TryParse(version.ToString().Split('.')[0], out browserVersion);
        }

        // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
        UInt32 mode = 10000;

        switch (browserVersion)
        {
            case 7:
                // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
                mode = 7000;
                break;
            case 8:
                // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
                mode = 8000;
                break;
            case 9:
                // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                mode = 9000;
                break;
            default:
                // use IE10 mode by default
                break;
        }

        return mode;
    }
}
}

刚刚实例化了这个类并将webbrowser控件提供给它:

WebBroweerControls.Form1 f1=新建WebBroweerControls.Form1此.webBrowser1;

请尝试以下操作

 var html = "<iframe width=\"425\" height=\"350\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" " +
                   "src=\"https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;" +
                   "geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471," +
                   "-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed\">" +
                   "</iframe>" +
                   "<br /><small><a href=\"https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas" +
                   "&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;" +
                   "sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7\" style=\"color:#0000FF;" +
                   "text-align:left\">View Larger Map</a></small>";

 webBrowser1.NavigateToString(html);

基本上相同的代码…只是使用NavigateToString将html参数加载到WebBrowser。

这似乎是WinForms WebBrowser控件,而不是WPF控件。请更改标记和标题。使用其中任何一个。控件大致相同,并且两者产生相同的结果。这正是浏览器所做的。我可以在.h中打开htmltml文档及其显示correctkly@user190084,此HTML在完整IE浏览器下工作吗?如果是,请签出。是的,在普通浏览器下它显示正确。我明天进入办公室后将签出帖子。谢谢!同样的问题。地图确实加载,然后在顶部覆盖灰色地图。请查看我的链接了解它的外观。