How to use CefSharp for WPF properly?

25,232

Hmm, I realize this is a few months back and it looks like the guide and code you applied was for the CefSharp1 code branch (that version did AFAIK only support x86). Note the WPF control for CefSharp1 and current master is quite different.

With CefSharp 33.0.0 just released I would suggest you try with that version of the NuGet and that you start out with getting everything running with the WPF example of CefSharp.MinimalExample first. I think the guide you used has been changed a bit since then. Not sure if it's ready for prime time yet though.

Finally there's a recent post on the CefSharp Google Group with a good write-up on the "DIY version of MinimalExample". Read the first two posts there which I think should still apply.

Share:
25,232
Flo
Author by

Flo

Working in the broadcasting business for a small german company.

Updated on February 12, 2020

Comments

  • Flo
    Flo over 4 years

    I created a new Wpf Project with VS2012. I right clicked on the Project and chose "Manage NuGet Packages". Then i installed the CefSharp Package for Wpf.

    Then i used this "guide" : https://github.com/cefsharp/CefSharp/blob/master/README.WPF.md

    Sadly i get like 4 Errors and i don't know how to get rid of them!

    These are the errors i get (i took out the path to the project with "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
    

    My XAML for the MainWindow:

    <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>
    

    Code behind for 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;
                }
            }
        }
    }
    

    The XAML and Code behind for the MainWindow are pretty much exactly the same as in the README.MD

    I also copied over those 2 files (libcef.dll and icudt.dll) from the 0.25.7 Binary package from github to the bin\Debug and bin\Release folders by hand.

    What am i doing wrong?

  • jep
    jep about 9 years
    Now I realize this is from a few months back, but I get the same problem using CefSharp 39.0.1 and the CefSharp.MinimalExample, as well as in my own code. But if I create the ChromiumWebBrowser manually in my .cs, it's fine. It's only when I (or MinimalExample) try to do it in the XAML that I get an error.
  • jornh
    jornh about 9 years
    What error specifically are you getting? If it's The name "XXXX" does not exist in the namespace "clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" can you get rid of it by closing the XAML file before starting debugging?
  • jep
    jep almost 9 years
    Ah, that indeed did get rid of it. It was never really stopping the build from happening, just erroneously claiming errors. Sorry, a bit new to this .NET stuff and still not used to "errors that aren't really errors" bit. :O
  • jornh
    jornh almost 9 years
    No, it's really confusing! I think github.com/cefsharp/CefSharp/wiki/… and the forum post it's linking to points to the possible underlying issue. If you can come up with a good phrase feel free to expand on the FAQ as it's a wiki page so editable to anyone with a GitHub account.