名称 ChromiumWebBrowser 在命名空间“clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf”中不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39612449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:55:39  来源:igfitidea点击:

The name ChromiumWebBrowser does not exist in the namespace "clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"

c#wpfxamlnamespacescefsharp

提问by Minkyu Kim

I had followed this linkto implement CefSharp applicaton.

我已按照此链接实施 CefSharp 应用程序。

But I have stuck while coding MainWindow.xaml.

但是我在编码时卡住了MainWindow.xaml

Blend for VS 2015 said,

Blend for VS 2015 说,

The name ChromiumWebBrowser does not exist in the namespace "clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"

名称 ChromiumWebBrowser 在命名空间“clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf”中不存在

But I'm installed CefSharp.Common and CefSharp.Wpf v51.0.0, cef.redist.x64 and cef.redist.x86 v3.2704.1432 with NuGet Package Manager.

但我安装了 CefSharp.Common 和 CefSharp.Wpf v51.0.0、cef.redist.x64 和 cef.redist.x86 v3.2704.1432 和 NuGet 包管理器。

I'm new on developing C# so I don't know how to solve this problem. Please help me to solve this error.

我是开发 C# 的新手,所以我不知道如何解决这个问题。请帮我解决这个错误。

This is my MainWindow.xaml

这是我的 MainWindow.xaml

<Window x:Class="StocktalkBrowser.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:StocktalkBrowser"
        xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <cefSharp:ChromiumWebBrowser Grid.Row="0"  Address="https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions" />
    </Grid>
</Window>


采纳答案by Nawed Nabi Zada

I just tried the link, and as I mentioned in the comments it compiles without any problem.

我刚刚尝试了这个链接,正如我在评论中提到的,它编译没有任何问题。

It is shown as error,  but you can ignore itCan be ignored.

它显示为错误,但您可以忽略它可以忽略。

No Preview availableAnd the preview is not available as well, I learned to live with it.

预览不可用而且预览版也不可用,我学会了忍受它。

CompilesNo errors when compiling

编译编译时没有错误

Program startsAnd the program starts up. No problem

程序开始然后程序启动。没问题

回答by Marko

For me the problem was that the solution platform was set to AnyCPU.
As far as I know, CefSharp does not support AnyCPU. Interestingly the solution ran just fine in Release mode, but in Debug mode I immediately got an error - the invocation of the constructor on type that matches ... the specified binding constraints threw an exception.

对我来说,问题是解决方案平台设置为 AnyCPU。
据我所知,CefSharp 不支持 AnyCPU。有趣的是,该解决方案在 Release 模式下运行良好,但在 Debug 模式下我立即出现错误 -the invocation of the constructor on type that matches ... the specified binding constraints threw an exception.

As soon as I changed the solution platform to be only x64, then the XAML error went away (The name ChromiumWebBrowser does not exist in the namespace “clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf”). And I could run the solution both in Debug and Release mode.

一旦我将解决方案平台更改为仅 x64,XAML 错误就消失了 ( The name ChromiumWebBrowser does not exist in the namespace “clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf”)。我可以在调试和发布模式下运行解决方案。

回答by dovid

its not supported in the XAML desginer, so load it in run time:

XAML 设计器不支持它,因此在运行时加载它:

  1. Remove the element from the XAMl, and instead place any container such as a Border:

    <Border x:Name="cefChromeContainer" />
    
  2. in the Constructor code, after InitializeComponent();call, craete the browser element and place into the container. even better to declare the browser in the class scoop:

    CefSharp.Wpf.ChromiumWebBrowser browser = new CefSharp.Wpf.ChromiumWebBrowser();
    
    public MainWindow()
    {
        InitializeComponent();
        cefChromeContainer.Content = browser;
        browser.Address = "https://stackoverflow.com";
    }
    
  1. 从 XAMl 中删除元素,并放置任何容器,例如 Border:

    <Border x:Name="cefChromeContainer" />
    
  2. 在构造函数代码中,InitializeComponent();调用后,创建浏览器元素并放入容器中。甚至更好地在类 scoop 中声明浏览器:

    CefSharp.Wpf.ChromiumWebBrowser browser = new CefSharp.Wpf.ChromiumWebBrowser();
    
    public MainWindow()
    {
        InitializeComponent();
        cefChromeContainer.Content = browser;
        browser.Address = "https://stackoverflow.com";
    }
    

回答by tomasofen

I had the same problem and i solve it changing configuration to from "debug" to "release" and using "x64" as platform.

我遇到了同样的问题,我解决了将配置从“调试”更改为“发布”并使用“ x64”作为平台的问题。

But it was not enought to change it from the solution menú, as i usually do. You need to go to visual studio main menú under "Compile > Configuration administration", as you can see in the following link from Microsoft:

但是,像我通常所做的那样,从解决方案菜单中更改它是不够的。您需要转到“编译>配置管理”下的visual studio主菜单,您可以在Microsoft的以下链接中看到:

https://docs.microsoft.com/es-es/visualstudio/ide/how-to-configure-projects-to-target-platforms?view=vs-2015&redirectedfrom=MSDN#Anchor_0

https://docs.microsoft.com/es-es/visualstudio/ide/how-to-configure-projects-to-target-platforms?view=vs-2015&redirectedfrom=MSDN#Anchor_0

This solution was in fact in the Readme.txt file for cefsharp, as stated in the "Documentation" link provided by saschadin his answer: https://github.com/cefsharp/CefSharp/blob/cefsharp/69/NuGet/Readme.txt

这个解决方案实际上在 cefsharp 的 Readme.txt 文件中,如saschad在他的回答中提供的“文档”链接中所述:https: //github.com/cefsharp/CefSharp/blob/cefsharp/69/NuGet/Readme 。文本

There you can read it:

在那里你可以阅读它:

Now I have it running like a charm :D

现在我让它像魅力一样运行:D

回答by saschad

You can read in the (Documentation) of the NuGet package, it's also necessary to add an app.manifestto your Application.

您可以阅读NuGet 包的(文档),还需要app.manifest向您的应用程序添加一个。