chromium embedded - CefSharp.Wpf WebView cannot accept input and the link clicked no response -
i used cefsharp.wpf in application. version: 1.25.7.
i hosted webpage via cefsharp webview. can host webpage in it. textbox in webview cannot accept input, , hyperlink cannot response.
here code. created wpf usercontrol named webpageoemviewer.
xaml:
<usercontrol x:class="webpageoemviewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="300"> <grid x:name="mainzone"> </grid> </usercontrol>
code behind:
public partial class webpageoemviewer : usercontrol, irequesthandler { private webview browser; public webpageoemviewer(string url) { initializecomponent(); cef.initialize(new settings { logseverity = logseverity.disable, packloadingdisabled = true }); var browsersettings = new browsersettings { applicationcachedisabled = true, pagecachedisabled = true }; browser = new webview(string.empty, browsersettings) { address = url, requesthandler = this, background = brushes.white }; browser.loadcompleted += browser_loadcompleted; cefjsobjectprocessor processor = new cefjsobjectprocessor(); browser.registerjsobject("cefjsobject", processor); mainzone.children.insert(0, browser); } public void view(string url) { if (browser.isbrowserinitialized) { browser.visibility = visibility.hidden; browser.load(url); } } public void close() { browser.dispose(); mainzone.children.remove(browser); } public static void shutdown() { thread.sleep(1000); if (cef.isinitialized) { cef.shutdown(); } } private void browser_loadcompleted(object sender, loadcompletedeventargs e) { dispatcher.invoke(new action(() => { browser.visibility = visibility.visible; })); } #region irequesthandler public bool getauthcredentials(iwebbrowser browser, bool isproxy, string host, int port, string realm, string scheme, ref string username, ref string password) { return false; } public bool getdownloadhandler(iwebbrowser browser, string mimetype, string filename, long contentlength, ref idownloadhandler handler) { return true; } public bool onbeforebrowse(iwebbrowser browser, irequest request, navigationtype naigationvtype, bool isredirect) { return false; } public bool onbeforeresourceload(iwebbrowser browser, irequestresponse requestresponse) { var headers = requestresponse.request.getheaders(); headers[constants.common.httpheaderfromkey] = constants.common.httpheaderfromvalue; requestresponse.request.setheaders(headers); return false; } public void onresourceresponse(iwebbrowser browser, string url, int status, string statustext, string mimetype, system.net.webheadercollection headers) { } #endregion internal class cefjsobjectprocessor { public event action<string> completed; private void completedinfo(string parameter) { if (completed != null) { completed(parameter); } } } } host usercontrol in window named filluserinfowindow xaml: <window x:class="filluserinfowindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:lcmb="clr-namespace:fclassroom.presentation.controls.messageboxes" title="填写基础信息" windowstartuplocation="centerscreen" width="770" height="530" loaded="filluserinfowindow_loaded"> <grid x:name="mainclient"> </grid> </window> code behind: public partial class filluserinfowindow : window { private webpageoemviewer _viewer; private string _url = string.empty; public filluserinfowindow() { initializecomponent(); } public filluserinfowindow(string url) { _url = url; initializecomponent(); } private void filluserinfowindow_loaded(object sender, routedeventargs e) { button closebutton = this.template.findname("closebutton", this) button; closebutton.click += closebutton_click; if(_viewer != null) { _viewer.visibility = visibility.visible; } loadwebpage(_url); } private void closebutton_click(object sender, routedeventargs e) { shutdown(); close(); } protected override void onmouseleftbuttondown(mousebuttoneventargs e) { dragmove(); base.onmouseleftbuttondown(e); } private void loadwebpage(string url) { application.current.dispatcher.invoke(new action(() => { if (_viewer == null) { _viewer = new webpageoemviewer(url); mainclient.children.insert(0, _viewer); } _viewer.visibility = visibility.visible; _viewer.view(url); })); } public void shutdown() { if(_viewer != null) { _viewer.close(); } } }
the webpage shown in window. search box , hyperlinks no response. tried latest cefsharp.wpf. both cannot work.
string address = "http://www.bing.com"; filluserinfowindow fills = new filluserinfowindow(address); fills.showdialog();
you can reproduce issue code above. time.
finally, got answer https://github.com/cefsharp/cefsharp/issues/1080#issuecomment-111969127
i sorry post duplicate thread online.
with amaitland's help. resolved issue. we needed remove onmouseleftbuttondown method.
thanks time.
Comments
Post a Comment