CEF的C#实现,很好用,推荐一下,下面是最简单的范例:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using CefSharp;
- namespace Test2
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- string HTML_STRING = "<div id='hello2'>你好世界,HelloWorld ~~~</div>";
- CefSharp.Wpf.WebView view;
- public MainWindow()
- {
- InitializeComponent();
- //开始CEF初始化:
- var setting = new Settings();
- setting.PackLoadingDisabled = true;
- if (CEF.Initialize(setting))
- {
- view = new CefSharp.Wpf.WebView();
- view.PropertyChanged += OnChanged;
- //view.Address = "http://www.google.com/";
- grid1.Children.Add(view);
- }
- }
- public void OnChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- if (e.PropertyName.Equals("IsBrowserInitialized", StringComparison.OrdinalIgnoreCase))
- {
- view.LoadHtml(string.Format(HTML_STRING));
- }
- }
- }
- }