簡體   English   中英

如何正確使用Ce​​fSharp for WPF?

[英]How to use CefSharp for WPF properly?

我用VS2012創建了一個新的Wpf項目。 我右鍵單擊了Project並選擇了“Manage NuGet Packages”。 然后我為Wpf安裝了CefSharp軟件包。

然后我用這個“指南”: https//github.com/cefsharp/CefSharp/blob/master/README.WPF.md

可悲的是,我得到了4個錯誤,我不知道如何擺脫它們!

這些是我得到的錯誤(我用“filepath”取出了項目的路徑):

Error   5   The type 'cefSharp:WebView' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.    "filepath"\Chromium\MainWindow.xaml 6   10  Chromium
Error   3   The name "WebView" does not exist in the namespace "clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf".  "filepath"\Chromium\MainWindow.xaml 6   9   Chromium

Error   6   The name 'Cef' does not exist in the current context    "filepath"\Chromium\MainWindow.xaml.cs  28  13  Chromium
Error   4   Assembly 'CefSharp.Wpf' was not found. Verify that you are not missing an assembly reference. Also, verify that your project and all referenced assemblies have been built. "filepath"\Chromium\MainWindow.xaml 4   22  Chromium

我在MainWindow的XAML:

<Window x:Class="Chromium.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" Title="MainWindow" Height="350" Width="525">
<Grid>
    <cefSharp:WebView x:Name="WebView" />
</Grid>

MainWindow.cs的代碼隱藏:

using System.ComponentModel;
using System.Windows;
using CefSharp;

namespace Chromium
{
    public partial class MainWindow 
    {
        public MainWindow()
        {
            InitializeComponent();

            WebView.PropertyChanged += OnWebViewPropertyChanged;

            Cef.Initialize(new Settings());
        }

        private void OnWebViewPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "IsBrowserInitialized":
                    if (WebView.IsBrowserInitialized)
                    {
                        WebView.Load("http://10.211.55.2:42000");
                    }

                    break;
            }
        }
    }
}

MainWindow的XAML和Code背后與README.MD完全相同

我還將這兩個文件(libcef.dll和icudt.dll)從github的0.25.7二進制包復制到bin \\ Debug和bin \\ Release文件夾中。

我究竟做錯了什么?

嗯,我意識到這是幾個月前, 看起來你應用的指南和代碼是CefSharp1代碼分支(該版本確實AFAIK只支持x86)。 注意 CefSharp1的WPF控件和當前的master是完全不同的。

剛剛發布的CefSharp 33.0.0我建議您嘗試使用該版本的NuGet, 首先使用CefSharp.MinimalExampleWPF示例運行所有內容。 我認為你使用的指南從那時起已經有所改變了。 雖然不確定它是否准備好迎接黃金時段。

最后有一篇關於CefSharp Google Group的帖子,其中有關於“MinimalExample的DIY版本”的精彩文章 閱讀我認為仍應適用的前兩個帖子。

我還通過NuGet庫開始了基於CefSharp 3的Hello World樣本集合。 如果您需要在WPF中使用CefSharp的101類型指導,請查看此處:

https://github.com/Dirkster99/KB

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM