我用 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 中的几乎完全相同
我还手动将 0.25.7 二进制包中的这 2 个文件(libcef.dll 和 icudt.dll)从 github 复制到 bin\Debug 和 bin\Release 文件夹。
我究竟做错了什么?
最佳答案
嗯,我意识到这是几个月前的事情,看起来您应用的指南和代码适用于 CefSharp1 代码分支(该版本 AFAIK 仅支持 x86)。 备注 CefSharp1 和当前的 WPF 控件 master
是完全不同的。
随着 CefSharp 33.0.0 刚刚发布,我建议您尝试使用该版本的 NuGet,然后开始使用 WPF example 运行所有内容。的 CefSharp.MinimalExample
第一的。我认为您使用的指南从那时起已经发生了一些变化。不确定它是否已经准备好迎接黄金时段。
最后,最近在 CefSharp Google Group 上发表了一篇帖子 a good write-up on the "DIY version of MinimalExample" .阅读那里的前两篇文章,我认为它们仍然适用。
关于wpf - 如何正确使用 CefSharp for WPF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24999355/