如何创建一个文本框,以使用CefSharp在Windows应用程序中打开Goog​​le搜索

时间:2019-04-01 03:36:04

标签: c# wpf visual-studio

我有一个CefSharp WPF应用程序,并且我需要一个文本框来打开Goog​​le在应用程序中搜索查询,而无需关闭并重新打开它。

我正在为它做一些事情。这可以实现吗?

1 个答案:

答案 0 :(得分:1)

是的,如果使用CefSharpBrowser控件是可以实现的。

this sample:中的WPF中实现了一个浏览器。 来自同一示例的此构造函数逻辑应该可以帮助您入门:

public BrowserTabViewModel(string address)
        {
            Address = address;
            AddressEditable = Address;

            GoCommand = new RelayCommand(Go, () => !String.IsNullOrWhiteSpace(Address));
            HomeCommand = new RelayCommand(() => AddressEditable = Address = CefExample.DefaultUrl);
            ExecuteJavaScriptCommand = new RelayCommand<string>(ExecuteJavaScript, s => !String.IsNullOrWhiteSpace(s));
            EvaluateJavaScriptCommand = new RelayCommand<string>(EvaluateJavaScript, s => !String.IsNullOrWhiteSpace(s));
            ShowDevToolsCommand = new RelayCommand(() => webBrowser.ShowDevTools());
            CloseDevToolsCommand = new RelayCommand(() => webBrowser.CloseDevTools());
            JavascriptBindingStressTest = new RelayCommand(() =>
            {
                WebBrowser.Load(CefExample.BindingTestUrl);
                WebBrowser.LoadingStateChanged += (e, args) =>
                {
                    if (args.IsLoading == false)
                    {
                        Task.Delay(10000).ContinueWith(t =>
                        {
                            WebBrowser.Reload();
                        });
                    }
                };
            });

            PropertyChanged += OnPropertyChanged;

            var version = string.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
            OutputMessage = version;
        }

希望这会有所帮助。