You are on page 1of 13

4/17/2021 Use of CefSharp under WPF - Programmer Sought

ProgrammerSought ☰

search

Use of CefSharp under WPF


tags: WPF C# wpf c# .net

Sta Using Facebook


Groups
Discover what's going on around you.
Find new events and groups near you.

Facebook® Visit Site

TOP

https://www.programmersought.com/article/76906790768/ 1/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

I have been using WPF's own WebBrowser Control, but because it uses the IE kernel, it is difficult to use, and
various errors are reported. So I changed to an open source browser package, CefSharp, which supports Winform
and WPF, embeds Chrome browser components and has more detailed documentation.

Open source project address

Official Chinese help document

installation
1. Install through Nuget, right click on the project -> Manage Nuget package -> search for
CefSharp in the opened interface, and install in turn CefSharp.Common with CefSharp.Wpf , As
for cef.redist.x64 with cef.redist.x86 It will be installed automatically.

TOP

https://www.programmersought.com/article/76906790768/ 2/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

2. Configure solution platform

Because CefSharp does not support ANYCPU, to configure x86, x64, click the menu Generate ->
Configuration Manager. Select the solution platform, click Edit, delete x64 and x86 first, then re-create it, and
reconfiguration is easier.

TOP

https://www.programmersought.com/article/76906790768/ 3/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

use
It can be added directly in the xaml file when used ChromiumWebBrowser Controls, but ChromiumWebBrowser Controls
especially consume memory, so dynamic addition in the code is also a good choice.

Add a browser in xaml

1. Xmal file header insert reference xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" , Add


controls as follows:

1 <Grid x:Name="ctrlBrowerGrid">
2 <wpf:ChromiumWebBrowser x:Name="Browser"/>
3 </Grid>

2. Access URL of operation control in cs file:

1 Browser.Load(“www.baidu.com”);

Dynamically add browsers

1. Add browser class: TOP

https://www.programmersought.com/article/76906790768/ 4/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

1 internal sealed class CollapsableChromiumWebBrowser : ChromiumWebBrowser


2 {
3 public CollapsableChromiumWebBrowser()
4 {
5 this.Loaded += this.BrowserLoaded;
6 }
7
8 private void BrowserLoaded(object sender, System.Windows.RoutedEventArgs e)
9 {
10 // Avoid loading CEF in designer
11 if (DesignerProperties.GetIsInDesignMode(this))
12 return;
13 // Avoid NRE in AbstractRenderHandler.OnPaint
14 ApplyTemplate();
15 CreateOffscreenBrowser(new Size(400, 400));
16 }
17 }

2. Dynamically add and operate controls:

1 CollapsableChromiumWebBrowser Browser = new CollapsableChromiumWebBrowser();


2 //Page insert control
3 ctrlBrowerGrid.Children.Add(Browser);
4 //The Load() method cannot be used here, an error will be reported.
5 Browser.Address = “www.baidu.com”;

Get Cookie and Html

1. Add cookie access class

1 public class CookieVisitor : ICookieVisitor copy


2 {
3 public static string Cookies = null;
4 public static string Html = null;
5 public event Action<object> Action;
6 public bool Visit(CefSharp.Cookie cookie, int count, int total, ref bool deleteCookie)
7 {
8 if(count == 0)
9 Cookies = null;
10
11 Cookies += cookie.Name + "=" + cookie.Value + ";";
12 deleteCookie = false;
13 return true;
14 }
15
16 public void Dispose()
17 {
18 if (Action != null) TOP

A ti ((Ht l C ki ))
https://www.programmersought.com/article/76906790768/ 5/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought
Action((Html, Cookies));
19
return;
20
}
21
}
22

2. Add Cookie and Html to get callback function

1 public async void RecieveCookie(object data)


2 {
3 (string html,string cookies) = ((string,string))data;
4 return;
5 }

3. Browser control to access URL and set callback

1 async void LoadWebBrowser()


2 {
3 Browser.FrameLoadEnd += Browser_FrameLoadEnd;
4 Browser.Address = "www.baidu.com";
5 }
6
7 private async void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
8 {
9 CookieVisitor.Html = await Browser.GetSourceAsync();
10 CookieVisitor visitor = new CookieVisitor();
11 visitor.Action += RecieveCookie;
12 Cef.GetGlobalCookieManager().VisitAllCookies(visitor);
13 return;
14 }

Zabbix disk performance for use (the iostat)


monitoring the linux

You May Like Sponsored Links by VDO.AI

TOP

https://www.programmersought.com/article/76906790768/ 6/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

Best Natural Hair Masks That Work Like Magic!

These Wonders Happen To Your Do Essential Oils Control Or 7 Herbs That Can Help You Lose
Body If You Start Consuming Reduce Snoring? 10 Oils To Help Weight
Two Eggs A Day You Sleep

Photos Of Shelter Dogs The Upset Mom Of A 3-Year-Old Famous Celebs Who Underwent
Moment They Realize They're Opens Husband's Car Trunk And Gender Reassignment Surgery
Being Adopted Uncovers A Secret That Was
Unknown For 7 Years

Intelligent Recommendation

wpf cefsharp support Chinese input TOP

https://www.programmersought.com/article/76906790768/ 7/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

Everyone in the development of WPF client program when it comes to browsers, then nothing more
than to use two kinds: first thought is Microso 's own WebBrowser, but o en comes with a lot of
things ...

How to install WPF using CEFSharp


Make a record, o en forget the configura on, and save me for those who
need it When using CEFSharp in WPF, it is easy to encounter problems. The
steps are now organized as follows: 1. Find ...

Con gure the cefsharp control of wpf (netcore3.1)


The first step is to install CefSharp.Wpf in NuGet, as shown below The second
step is to modify the project proper es, the pla orm is changed to x86 or x64,
and AnyCPU cannot be used, as shown in th...

Use NLog under WPF


1 First, now Nlog from nuget, since I am using .net core 3.0, I download the Nlog as shown in the figure.
2 Create Nlog.config configura on file 3. Write a Logger class where thread and thread lock a...

[Four] C # WPF-based access to do the universal reptile --- use CefSh


arp extend a helper class httpClient
Example of use: string url =
"h p://192.168.1.97:8001/api/NEWICM/NewCompanyModule/NewCompanyDetailInfo/GetContactInfo";
Dic onary<string, string> query = new Dic onary<string, st...

TOP

https://www.programmersought.com/article/76906790768/ 8/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

More Recommendation

Use CEFSharp to display web pages in WPF (can achi


eve hybrid development on the PC side, Web and har
dware interaction)
Recently I met a Web applica on that needs to call a hardware interface such
as an ID card reader. Packaging an OCX control according to the general solu on is done. But the
problem arises. At prese...

Solve the problem that the CefSharp WPF control ca


nnot use the input method to input Chinese (the cod
e has been submitted to github)
First of all, all the code in this ar cle has been submi ed to github, you can get
it directly from github: h ps://github.com/starts2000/CefSharp, hope to help friends in need.
Introduc on to CEF ...

Use CEfSharp tour (4) cefsharp call F12


How does Cefsharp call func ons similar to F12?...

Use CEfSharp Journey (5) CEFSharp Isolate Cookie


How to isolate that? I have been reluctant to use program applica on domain isola on in recent
projects, and finally found a way to achieve it. Put forward to make a note: The four key sentences in ...

Use cefsharp browser to enlarge TOP

https://www.programmersought.com/article/76906790768/ 9/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

(1) If the browser loca on has a problem, you need to set Cef.EnableHighDPISupport (); (2) To zoom the
browser to set browser.SetZoomLevel (1.25); void webbrowser_FrameLoadEnd(object sender, F...

Related Posts
Basic use of CefSharp For WPF
Use cefsharp in wpf to load local html webpage and realize the interac on of cs and js, and
cefsharp supports any cpu
[ ]C# Based on WPF, use CefSharp to do universal crawler
[ ]C# Based on WPF, use CefSharp to do universal crawler
Using cefsharp in WPF
CefSharp For WPF hide scrollbars
CefSharp For WPF hide scrollbars
WPF CefSharp Rep le
wpf integrated cefSharp
Cefsharp for WPF basics

Learn to Trade Forex


Low Spreads
Trade with Advanced
Charts
24/5 Market Access for
Gold & Forex

OPEN AN ACCOUNT

Losses can exceed your


deposited funds.

TOP

https://www.programmersought.com/article/76906790768/ 10/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

Popular Posts
JavaFX learning example 6
jQuery or selector?
LeetCode 011 container with the most water
Detailed C language structure
Elementary Data Structure
C # achieve the specified cell operates EXCEL
Small trap on xxxxxxRepository.search () method of a page
Python implements convolu on calcula on, smoothing filter, Gaussian filter, Sobel operator,
Prewi operator
[Solu on] Luogu P2661 [NOIP2015] informa on transmission and collec on
Study notes for the MDSeq-R package (direct paste code)

TOP

https://www.programmersought.com/article/76906790768/ 11/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

Recommended Posts
Perfect number
Using tags in Cocos2d-x Lua
The Java Evolu on of the Eclipse Collec on
Use Linux Raspberry Pi to read JY61 serial port data
About adding a final in the code set to facilitate the reasonable alloca on of applica on memory
--- HTML front-end
MyTools TOP

https://www.programmersought.com/article/76906790768/ 12/13
4/17/2021 Use of CefSharp under WPF - Programmer Sought

Explain Angular's custom instruc ons in detail


AcWing 1012. Sister ci es
Three advantages of network monitoring

Related Tags
WPF
CefSharp
technology
C#
c#
xaml
wpf
CEFSharp
NLog
h pclient

Copyright © 2018-2021 - All Rights Reserved - www.programmersought.com

TOP

https://www.programmersought.com/article/76906790768/ 13/13

You might also like