我用 VS2012 创建了一个新的 Wpf 项目。我右键单击项目并选择“管理 NuGet 包”。然后我为 Wpf 安装了 CefSharp 包。
然后我使用了这个“指南”:https ://github.com/cefsharp/CefSharp/blob/master/README.WPF.md
可悲的是,我得到了 4 个错误,我不知道如何摆脱它们!
这些是我得到的错误(我用“文件路径”取出了项目的路径):
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
我的主窗口 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 和代码与 README.MD 中的代码几乎完全相同
我还手动从 github 的 0.25.7 二进制包中复制了这 2 个文件(libcef.dll 和 icudt.dll)到 bin\Debug 和 bin\Release 文件夹。
我究竟做错了什么?