How to use CefSharp for WPF properly?

Flo picture Flo · Jul 28, 2014 · Viewed 22.7k times · Source

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?

Answer

jornh picture jornh · Oct 11, 2014

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.