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

不打扰是莪最后的温柔 提交于 2019-12-09 03:34:23

问题


I had followed this link to implement CefSharp applicaton.

But I have stuck while coding MainWindow.xaml.

Blend for VS 2015 said,

The name ChromiumWebBrowser does not exist in the namespace "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.

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

This is my 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>


回答1:


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

Can be ignored.

And the preview is not available as well, I learned to live with it.

No errors when compiling

And the program starts up. No problem




回答2:


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.

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.




回答3:


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

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



回答4:


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



来源:https://stackoverflow.com/questions/39612449/the-name-chromiumwebbrowser-does-not-exist-in-the-namespace-clr-namespacecefsh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!