原文:CefSharp For WPF基本使用

Nuget引用

CefSharp.Wpf
CefSharp.Common
cef.redist.x64
cef.redist.x86

直接搜索安装CefSharp.Wpf即可,因为CefSharp.Wpf依赖于其他三个包,所以会自动安装四个包

 

先更改设置

指定特定的平台,x64或者x86,默认是Any CPU
不进行配置的话,CefSharp是不支持Any CPU的

 

WPF写法

xmlns:cefSharpWPF="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
<cefSharpWPF:ChromiumWebBrowser Address="url"></cefSharpWPF:ChromiumWebBrowser>

Any CPU的支持

using System.Windows;
using System;
using System.Runtime.CompilerServices;
using CefSharp;
using System.IO;
using System.Reflection;
using System.Windows.Threading;
using CefSharpWpfDemo.Log; namespace CefSharpWpfDemo
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public App()
{
// Add Custom assembly resolver
AppDomain.CurrentDomain.AssemblyResolve += Resolver;
//Any CefSharp references have to be in another method with NonInlining
// attribute so the assembly rolver has time to do it's thing.
InitializeCefSharp();
} [MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeCefSharp()
{
var settings = new CefSettings(); // Set BrowserSubProcessPath based on app bitness at runtime
settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
"CefSharp.BrowserSubprocess.exe"); // Make sure you set performDependencyCheck false
Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
} // Will attempt to load missing assembly from either x86 or x64 subdir
// Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
private static Assembly Resolver(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("CefSharp"))
{
string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
Environment.Is64BitProcess ? "x64" : "x86",
assemblyName); return File.Exists(archSpecificPath)
? Assembly.LoadFile(archSpecificPath)
: null;
} return null;
}
}
}

相关资料

https://github.com/cefsharp/CefSharp/issues/1714

示例代码

https://github.com/zLulus/NotePractice/tree/dev3/WPF/CefSharpWpfDemo

官方资料

https://www.codeproject.com/Articles/881315/Display-HTML-in-WPF-and-CefSharp-Tutorial-Part
https://github.com/cefsharp/CefSharp/wiki/Quick-Start
http://cefsharp.github.io/

CefSharp For WPF基本使用的更多相关文章

  1. CefSharp For WPF自定义右键菜单栏

    原文:CefSharp For WPF自定义右键菜单栏 初始化 <!--浏览器--> <cefSharpWPF:ChromiumWebBrowser Name="webBr ...

  2. CefSharp For WPF隐藏滚动条

    效果:开始的时候会显示几秒,之后就不会再显示了 <!--浏览器--> <cefSharpWPF:ChromiumWebBrowser Name="webBrowser&qu ...

  3. CefSharp For WPF响应页面点击事件

    初始化 <!--浏览器--> <cefSharpWPF:ChromiumWebBrowser Name="webBrowser" Grid.Row="0 ...

  4. 修复CefSharp浏览器组件中文输入Bug

    概述 最近在win10上开发wpf应用,需要将CefSharp中wpf版本的浏览器组件(版本号v51.0.0)嵌入到应用中,但是发现不支持中文输入,GitHub上有这个问题的描述,参照其提到的方法可以 ...

  5. 使用CefSharp在.Net程序中嵌入Chrome浏览器(一)——简介

    有的时候,我们需要在程序中嵌入Web浏览器,其实.Net Framework中本身就提供了WebBrowser控件,本身这个是最简单易用的方案,但不知道是什么原因,这个控件在浏览网页的时候有些莫名的卡 ...

  6. C#:在AnyCPU模式下使用CefSharp

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲述如何在AnyCPU模式下使用CefSharp 因为在某些情况下,不得不用AnyCPU,但是CefS ...

  7. WPF学习目录

    基本概念 数据源Source-目标Target WPF生命周期 App.xaml 依赖属性 WPF路由 线程操纵UI问题 利用属性中设置.查看DataContext/Command等 分析布局 写数据 ...

  8. CefSharp部分效果实现

    CefSharp For WPF隐藏滚动条 CefSharp For WPF自定义右键菜单栏 CefSharp For WPF响应页面点击事件

  9. 使用CefSharp在C#访问网站,支持x86和x64

    早已久仰CefSharp大名,今日才得以实践,我其实想用CefSharp来访问网站页面,然后抓取html源代码进行分析,如果使用自带的WebBrowser控件,可能会出现一些不兼容js的错误. Cef ...

随机推荐

  1. shell脚本if条件总结

    原文链接:https://geniuspeng.github.io/2018/03/12/shell-if/ shell编程中,if-then是一种常见的控制流命令,而if的条件判断一般采用内置命令t ...

  2. js实现操作等待提示loading……

    js实现操作等待功能,防止重复提交,界面友好,底部为灰色遮罩层,防止用户重复操作. 先看效果图:   接着看js代码: //关闭等待窗口 function closeWaiting() { var b ...

  3. URAL 1542. Autocompletion 字典树

    给你最多10w个单词和相应的频率 接下来最多1w5千次询问 每次输入一个字符串让你从前面的单词中依照频率从大到小输出最多10个以该字符串为前缀的单词 開始把单词建成了字典树 然后每次询问找到全部满足条 ...

  4. 【solr专题之四】在Tomcat 中部署Solr4.x 分类: H_HISTORY 2014-07-17 16:08 1286人阅读 评论(0) 收藏

    1.安装Tomcat (1)下载并解压至/opt/tomcat中 # cd /opt/jediael # tar -zxvf apache-tomcat-7.0.54.tar.gz # mv apac ...

  5. thinkphp,onethink,thinkox验证码不显示

    使用验证码的时候,一开始正常,后来不显示了 网上说是utf-8的编码问题,什么bom去掉,转化为无bom的格式 我都试了,没用 后来知道是在调用验证码的地方  写上 Public function v ...

  6. java并发api总结

    开发十年,就只剩下这套架构体系了! >>>   1.java.util.concurrent包 1.1 Executors Executor:接口,仅有一个方法为execute(Ru ...

  7. MRTG Monitoring with ESXi Hosted Guest Return ‘interface is commented * has no ifSpeed property’

    MRTG Monitoring with ESXi Hosted Guest Return ‘interface is commented * has no ifSpeed property’ Rec ...

  8. [Java][Spring]Spring事务不起作用 问题汇总

    [Java][Spring]Spring事务不起作用 问题汇总 http://blog.csdn.net/szwangdf/article/details/41516239

  9. C++ 中的 const 类型变量

    之前总感觉C/C++中有const 限定的变量是个很头痛的问题,一会儿能够变.一会儿不能够变,一会儿把const赋给nonconst,一会儿又把nonconst赋给const,头都被它搞大了.今天刚好 ...

  10. svn hook pre-commit

    #!/bin/bashexport LANG="zh_CN.UTF-8" #确保中文日志显示正常,便于统计日志REPOS="$1"TXN="$2&qu ...