Getting or Setting HTML Content in CefSharp

Опубликовано: 16 Ноябрь 2017
на канале: Embedded Browsers
20,379
62

A step-by-step guide on getting or setting HTML content in CefSharp.
You can get the source code of this sample in the GitHub repository: https://github.com/cefsharptutorials/...
About CefSharp: https://cefsharp.github.io/

Previous Tutorials:

CefSharp Basics: Display an HTML5/CSS3 Webpage:
   • CefSharp Basics: Display an HTML5/CSS...  

URL Navigation Using CefSharp:
   • URL Navigation Using CefSharp  

Executing JavaScript from the .NET Side Using CefSharp:
   • Executing JavaScript from the .NET Si...  

Injecting a .NET Object into JavaScript Using СefSharp:
   • Injecting a .NET Object into JavaScri...  

Remote Debugging Using СefSharp:
   • Remote Debugging Using СefSharp  

Transcript:

00:03 First of all we need to create a WPF project with x86 or x64 configuration and reference the CefSharp library via NuGet. You can find the detailed instructions in the previous tutorials.

00:15 Next Step is MainWindow Markup.

00:17 Add the CefSharp XML namespace to the MainWindow.

00:26 Create two columns and two rows in the root grid.

00:46 Add the ChromiumWebBrowser to the left side of the window.

00:50 Specify the initial address and create the FrameLoadEnd handler.

01:11Add the SetHTML Button to the top right cell of the grid, set its name and create the click event handler.

01:34 Add the TextBox to the bottom right cell of the grid. This TextBox will be used for displaying and modifying the HTML content of the ChromiumWebBrowser.

01:52 Now Let`s Implement the MainWindow Behaviour.

01:55 Let’s update the TextBox content.
Go to the FrameLoadEnd event handler and open the Dispatcher.BeginInvoke instruction.

02:10 Inside of the BeginInvoke fill the HtmlTextBox.Text property value with the result of the BrowserView.GetSourceAsync method.
Please note that the delegate used in the BeginInvoke instruction should be marked as async.

02:23 This handler will update the text box content every time the browser finishes loading any frame.

02:28 Go to the Button click handler.
Inside this handler call the BrowserView.LoadHTML method and pass the text box content as its argument.

02:42 So, Now You Can Build and Launch Your Application.

#EmbeddedBrowsers
#HTMLContetn
#GettingOrSetting