CEF的C#實現,可以實現用Chrome來渲染UI,期待已久的UI解決方案。

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));
            }
        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章