我有一个CefSharp WPF应用程序,并且我需要一个文本框来打开Google在应用程序中搜索查询,而无需关闭并重新打开它。
我正在为它做一些事情。这可以实现吗?
答案 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;
}
希望这会有所帮助。