Archive

Archive for the ‘MSBuild’ Category

CefSharp Example WPF Getting Started

08/11/2014 1 comment

Q1. What is CefSharp?

Ans: .NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework

CefSharp would be preferable over Awesomium considering the implications of getting the
wrapper to work with x64 which would definitely be a challenge (You may have code it all
in your home time since you may not be able to at work,so consider how you are going
to balance home and work,yes sarcasm)

Q2. Where are the CefSharp binaries  for Microsoft dot net(.NET) ?

Ans: Currently at https://github.com/cefsharp/CefSharp/releases and going strong until thedevelopers abandon ship.But where are the binaries? I do’nt see them all I see are source
codes zip and tars (for windows seesh overkill). You can scroll down the page and you’ll
see ‘older’ binaries…who needs them.WELL I THINK YOU HAVE TO DOWNLOAD THE
BUILD IT YOURSELF.(This is good in away,so get VS2013 and build it)

Q3. Is there an example of how to embed and use CefSharp with WPF? (Thats what you want it for right?)

Ans: https://codeload.github.com/cefsharp/CefSharp.MinimalExample/zip/master (until this link lasts) has a ‘minimal example’

Q4. But that looks like an overkill minimal example and it won’t build ?

Ans: You have to get the release from the link in Answer 2 and build the dll (say for x64) and
add reference to the files , plus all the other c++ dll should be in the bin or so.

DOESN’T WORK ?

1. YOU NEED TO BUILD FOR X64 OR X86 YOU CAN NOT SIMPLY BUILD FOR ANY.

one-does-not-8oq0q4
2. SO YOU NEED TO HAVE TO BUILDS FOR YOUR WPF APPLICATION (CORRECT ME IF I’M WRONG IN THE COMMENTS)3. SO CHANGE YOU BUILD CONFIGURATION TO X64 FROM BUILD MENU – CONFIGURATION MANAGER (OR X86 PROVIDED YOU HAVE THE CEFSHARP BUILD FOR 32BIT (COMPLICATED EMBEDDED FRAMEWORK INDEED) (Blame it on Chromium for waiting till 2014 for a x64 build) (Well don’t blame anyone since things are really made easy for you or so to get started,yes this is just the painful beginning depending on how you plan to use its powers sigh!)

Below is the dll ref to a sample WPF app I created in the same example I downloaded

D:\CEF\CefSharp.MinimalExample-master\packages\CefSharp.Wpf.33.0.2\CefSharp\x64\CefSharp.Wpf.dll
D:\CEF\CefSharp.MinimalExample-master\packages\CefSharp.Common.33.0.2\CefSharp\x64\CefSharp.Core.dll
D:\CEF\CefSharp.MinimalExample-master\packages\CefSharp.Common.33.0.2\CefSharp\x64\CefSharp.dll

Code is as below:

YOU NEED TO INIT AS BELOW OR FAIL !!!!

public partial class App : Application
   {
       public App()
       {
           Cef.Initialize(new CefSettings());
       }
   }

XAML WINDOW

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <wpf:ChromiumWebBrowser Grid.Row="0"
                          Address="http://google.com/"
                          WebBrowser="{Binding WebBrowser, Mode=OneWayToSource}"
                          Title="{Binding Title, Mode=TwoWay}" />
        <StatusBar Grid.Row="1">
            <ProgressBar HorizontalAlignment="Right"
                         IsIndeterminate="{Binding WebBrowser.IsLoading}"
                         Width="100"
                         Height="16"
                         Margin="3" />
            <Separator />
            <!-- TODO: Could show hover link URL here -->
            <TextBlock />
        </StatusBar>
    </Grid>
</Window>
Advertisements
Categories: C#, MSBuild, WPF Tags: