原文: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. js进阶ajax基本用法(创建对象,连接服务器,发送请求,获取服务器传过来的数据)

    js进阶ajax基本用法(创建对象,连接服务器,发送请求,获取服务器传过来的数据) 一.总结 1.ajax的浏览器的window对象的XMLHtmlRequest对象的两个重要方法:open(),se ...

  2. iOS调试 - 基本技巧

    在程序中,无论是你想弄清楚为什么数组中有3个对象而不是5个,或者为什么一个新的玩家开始之后,游戏在倒退——调试在这些处理过程中是比较重要的一部 分.通过本文的学习,我们将知道在程序中,可以使用的大多数 ...

  3. JavaEE 技术选型建议,server配置,部署策略

    基础设施环境 # 总体採用 centos6.5 + nginx + tomcat7.0 负载均衡:nginx 配置,使用 nginx 作为负载均衡.权重配置. 在web层做到水平扩展. 以及配置日志格 ...

  4. java痛苦学习之路[十二]JSON+ajax+Servlet JSON数据转换和传递

    1.首先client须要引入 jquery-1.11.1.js 2.其次javawebproject里面须要引入jar包  [commons-beanutils-1.8.0.jar.commons-c ...

  5. ios开发网络学习十二:NSURLSession实现文件上传

    #import "ViewController.h" // ----WebKitFormBoundaryvMI3CAV0sGUtL8tr #define Kboundary @&q ...

  6. WP8.1:onedrive操作

    小梦今天给大家分享一下windows phone 8.1开发 onedrive中的一些操作: Windows phone 8.1 中 onedrive 登录 Windows phone 8.1 中 o ...

  7. java生成6位随机数

    生成6位随机数(不会是5位或者7位,仅只有6位): System.out.println((int)((Math.random()*9+1)*100000)); 同理,生成5位随机数: System. ...

  8. ios开发事件处理之:五:事件的响应

  9. php课程 5-18 数组排序和合并拆分函数有哪些

    php课程  5-18   数组排序和合并拆分函数有哪些 一.总结 一句话总结:分类来记.这些函数自己都可以写,费点时间而已. 1.array_combine()和array_merge()的区别是什 ...

  10. [Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def

    What about the situation in which we aren’t specifying the number of columns or rows to be repeated? ...