1

I have a solution with multiple projects. The principle project is a WinFormsApplication that references a WPF project. I have tried to incorporate a WPF UserControl (defined in the WPF project) that contains CefSharp ChromiumWebBrowser in a Form using ElementHost.

public partial class WebForm : Form
{
    private ElementHost elementHostWeb;
    public WebForm()
    {
        InitializeComponent();
        elementHostWeb = new ElementHost();
        elementHostWeb.Height = this.Height;
        elementHostWeb.Width = this.Width;
        elementHostWeb.Child = new WebWPFUserControl();
    }
}

WPF UserControl:

<UserControl x:Class="WpfApplication.WebWPFUserControl"
    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:WpfApplication"
    xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
    mc:Ignorable="d"
    Title="WebWPFUserControl" Height="350" Width="525">
<Grid>
    <cefSharp:ChromiumWebBrowser Grid.Row="0"
    Address="https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions" />
</Grid>

When I tray to open the Form I get the following error:

enter image description here

pcCopyDev
  • 11
  • 3
  • Why is your WPF-File a Window and not a ? – FoldFence Mar 07 '17 at 10:01
  • My fault, I have tried to describe the situation with different and simplified code and I have wrong. However you'll get the same error with the UserControl as well. – pcCopyDev Mar 07 '17 at 10:13
  • I know the problem, its something with your clr link, have you tried to delete the assembly=....? – FoldFence Mar 07 '17 at 10:17
  • Which kind of assembly Should I delete? – pcCopyDev Mar 07 '17 at 10:29
  • try to change xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" to xmlns:cefSharp="clr-namespace:CefSharp.Wpf;" otherwise you can have a look on this question: http://stackoverflow.com/questions/12885371/assembly-reference-not-found-in-xaml-but-code-compiles-when-referenced-in-xaml it may help you – FoldFence Mar 07 '17 at 11:59
  • Thank you! Now it works. I added the CEF dll (using nuget package manager) also to the main project (WinFormsApplication) and not only in the WPFApplication. – pcCopyDev Mar 07 '17 at 15:11
  • Great to here ! You can write your own answer to help future user with the same problem =) – FoldFence Mar 07 '17 at 15:33

0 Answers0