如何使用 CefSharp 创建一个在 Windows 应用程序中打开 Google 搜索的文本框

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

我正在为此努力。这是可以实现的吗?



蛊毒传说
浏览 104回答 1
1回答

繁星点点滴滴

是的,如果您使用 CefSharpBrowser 控件,这是可以实现的。此示例中有一个在 WPF 中实现的浏览器: . 来自同一示例的构造函数逻辑应该可以帮助您入门:public BrowserTabViewModel(string address)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Address = address;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddressEditable = Address;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GoCommand = new RelayCommand(Go, () => !String.IsNullOrWhiteSpace(Address));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HomeCommand = new RelayCommand(() => AddressEditable = Address = CefExample.DefaultUrl);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExecuteJavaScriptCommand = new RelayCommand<string>(ExecuteJavaScript, s => !String.IsNullOrWhiteSpace(s));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EvaluateJavaScriptCommand = new RelayCommand<string>(EvaluateJavaScript, s => !String.IsNullOrWhiteSpace(s));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowDevToolsCommand = new RelayCommand(() => webBrowser.ShowDevTools());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseDevToolsCommand = new RelayCommand(() => webBrowser.CloseDevTools());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JavascriptBindingStressTest = new RelayCommand(() =>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebBrowser.Load(CefExample.BindingTestUrl);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebBrowser.LoadingStateChanged += (e, args) =>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (args.IsLoading == false)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Task.Delay(10000).ContinueWith(t =>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebBrowser.Reload();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PropertyChanged += OnPropertyChanged;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var version = string.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputMessage = version;&nbsp; &nbsp; &nbsp; &nbsp; }希望这可以帮助。
打开App,查看更多内容
随时随地看视频慕课网APP