Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WPF Browser Application (XBAP) Example #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CefSharp.MinimalExample.WpfXBap/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--https://docs.microsoft.com/en-us/dotnet/framework/deployment/how-the-runtime-locates-assemblies-->
<runtime>
<!--<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CefSharp" publicKeyToken="40c4b6fc221f4138" culture="neutral" />
<codeBase version="63.0.3.0" href="x86/CefSharp.dll" />
<codeBase version="63.0.3.0" href="x64/CefSharp.dll" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="CefSharp.BrowserSubprocess" publicKeyToken="40c4b6fc221f4138" culture="neutral" />
<codeBase version="63.0.3.0" href="x86/CefSharp.BrowserSubprocess.dll" />
<codeBase version="63.0.3.0" href="x64/CefSharp.BrowserSubprocess.dll" />
</dependentAssembly>

<probing privatePath="x86;x64" />
</assemblyBinding>-->
</runtime>
</configuration>
9 changes: 9 additions & 0 deletions CefSharp.MinimalExample.WpfXBap/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="CefSharp.MinimalExample.WpfXBap.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CefSharp.MinimalExample.WpfXBap"
StartupUri="Page1.xaml">
<Application.Resources>

</Application.Resources>
</Application>
96 changes: 96 additions & 0 deletions CefSharp.MinimalExample.WpfXBap/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows;
using CefSharp;

namespace CefSharp.MinimalExample.WpfXBap
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
#region Constructor
/// <summary>
///
/// </summary>
public App()
{
IBrowserProcessHandler browserProcessHandler;

AppDomain.CurrentDomain.AssemblyResolve += Resolver;

browserProcessHandler = null;

//Any CefSharp references have to be in another method with NonInlining
// attribute so the assembly rolver has time to do it's thing.
InitializeCefSharp(browserProcessHandler);
}
#endregion

#region Protected Methods
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnExit(ExitEventArgs e)
{
Cef.Shutdown();

base.OnExit(e);
}
#endregion

#region Private Methods
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeCefSharp(IBrowserProcessHandler browserProcessHandler)
{
CefSettings settings;

try
{
settings = new CefSettings();

// Set BrowserSubProcessPath based on app bitness at runtime
settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe");

Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: browserProcessHandler);
}
catch (FileNotFoundException exception)
{
Debug.WriteLine(exception.Message);
}
}
/// <summary>
/// Will attempt to load missing assembly from either x86 or x64 subdir
/// Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <returns></returns>
private static Assembly Resolver(object sender, ResolveEventArgs e)
{
Assembly resolvedAssembly;
string assemblyName;
string archSpecificPath;

resolvedAssembly = null;

if (e.Name.StartsWith("CefSharp") == true)
{
//https://github.com/cefsharp/CefSharp/issues/1714
assemblyName = e.Name.Split(new[] { ',' }, 2)[0] + ".dll";
archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", assemblyName);

//LoadFile does not load files into the load-from context, and does not resolve dependencies using the load path
resolvedAssembly = File.Exists(archSpecificPath) ? Assembly.LoadFile(archSpecificPath) : null;
}

return resolvedAssembly;
}
#endregion
}
}
165 changes: 165 additions & 0 deletions CefSharp.MinimalExample.WpfXBap/CefSharp.MinimalExample.WpfXBap.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\CefSharp.Wpf.63.0.3\build\CefSharp.Wpf.props" Condition="Exists('..\packages\CefSharp.Wpf.63.0.3\build\CefSharp.Wpf.props')" />
<Import Project="..\packages\CefSharp.Common.63.0.3\build\CefSharp.Common.props" Condition="Exists('..\packages\CefSharp.Common.63.0.3\build\CefSharp.Common.props')" />
<Import Project="..\packages\cef.redist.x86.3.3239.1723\build\cef.redist.x86.props" Condition="Exists('..\packages\cef.redist.x86.3.3239.1723\build\cef.redist.x86.props')" />
<Import Project="..\packages\cef.redist.x64.3.3239.1723\build\cef.redist.x64.props" Condition="Exists('..\packages\cef.redist.x64.3.3239.1723\build\cef.redist.x64.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EB0C38C3-908F-49DB-A880-BF21581BDC10}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>CefSharp.MinimalExample.WpfXBap</RootNamespace>
<AssemblyName>CefSharp.MinimalExample.WpfXBap</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<EnableSecurityDebugging>true</EnableSecurityDebugging>
<StartAction>URL</StartAction>
<HostInBrowser>true</HostInBrowser>
<TargetZone>Internet</TargetZone>
<GenerateManifests>true</GenerateManifests>
<SignManifests>True</SignManifests>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport>
<PublishUrl>publish\</PublishUrl>
<Install>false</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>false</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
<Page Include="Page1.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Page1.xaml.cs">
<DependentUpon>Page1.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="CefSharp.MinimalExample.WpfXBap_TemporaryKey.pfx" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Include="Properties\app.manifest" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<PropertyGroup>
<StartArguments />
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>CefSharp.MinimalExample.WpfXBap_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>5257D40BFE8076154F7FBF6B1CD066E24301F5B4</ManifestCertificateThumbprint>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\cef.redist.x64.3.3239.1723\build\cef.redist.x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x64.3.3239.1723\build\cef.redist.x64.props'))" />
<Error Condition="!Exists('..\packages\cef.redist.x86.3.3239.1723\build\cef.redist.x86.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x86.3.3239.1723\build\cef.redist.x86.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Common.63.0.3\build\CefSharp.Common.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.63.0.3\build\CefSharp.Common.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Common.63.0.3\build\CefSharp.Common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.63.0.3\build\CefSharp.Common.targets'))" />
<Error Condition="!Exists('..\packages\CefSharp.Wpf.63.0.3\build\CefSharp.Wpf.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Wpf.63.0.3\build\CefSharp.Wpf.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Wpf.63.0.3\build\CefSharp.Wpf.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Wpf.63.0.3\build\CefSharp.Wpf.targets'))" />
</Target>
<Import Project="..\packages\CefSharp.Common.63.0.3\build\CefSharp.Common.targets" Condition="Exists('..\packages\CefSharp.Common.63.0.3\build\CefSharp.Common.targets')" />
<Import Project="..\packages\CefSharp.Wpf.63.0.3\build\CefSharp.Wpf.targets" Condition="Exists('..\packages\CefSharp.Wpf.63.0.3\build\CefSharp.Wpf.targets')" />
</Project>
Binary file not shown.
40 changes: 40 additions & 0 deletions CefSharp.MinimalExample.WpfXBap/Page1.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Page x:Class="CefSharp.MinimalExample.WpfXBap.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CefSharp.MinimalExample.WpfXBap"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="700"
Title="Page1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<cefSharp:ChromiumWebBrowser x:Name="browser"
Address="http://www.google.com"
Title="{Binding Title, Mode=OneWayToSource}">
<FrameworkElement.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="{Binding Value, ElementName=angleSlider}" />
</TransformGroup>
</FrameworkElement.LayoutTransform>
</cefSharp:ChromiumWebBrowser>
<DataGrid Name="DataRecords" Grid.Row="1" AutoGenerateColumns="False"
CanUserAddRows="False" IsReadOnly="True" EnableColumnVirtualization="False" EnableRowVirtualization="True"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<DataGrid.Columns>
<DataGridTextColumn Header="Column 1" />
<DataGridTextColumn Header="Column 2" />
<DataGridTextColumn Header="Column 3" />
<DataGridTextColumn Header="Column 4" />
<DataGridTextColumn Header="Column 5" />
<DataGridTextColumn Header="Column 6" />
<DataGridTextColumn Header="Column 7" />
<DataGridTextColumn Header="Column 8" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Page>
28 changes: 28 additions & 0 deletions CefSharp.MinimalExample.WpfXBap/Page1.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CefSharp.MinimalExample.WpfXBap
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
}
}
Loading