Skip to content

Instantly share code, notes, and snippets.

@WolfieWerewolf
Created September 23, 2015 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WolfieWerewolf/2f3453d25942a0ceb8ef to your computer and use it in GitHub Desktop.
Save WolfieWerewolf/2f3453d25942a0ceb8ef to your computer and use it in GitHub Desktop.
CefSharp 3 Example of two Chromium WPF "tabs" in the same View
This is a direct modification of the CefSharp.Wpf.Example. Just replace the existing Xaml with this code.
Let me know if you have any questions. wolfiewerewolf@gmail.com.
<UserControl x:Class="CefSharp.Wpf.Example.Views.BrowserTabView"
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:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" xmlns:local="clr-namespace:CefSharp.Wpf.Example.ViewModels"
mc:Ignorable="d"
d:DesignWidth="640"
d:DesignHeight="480"
d:DataContext="{d:DesignInstance local:BrowserTabViewModel}">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</UserControl.Resources>
<DockPanel>
<Grid DockPanel.Dock="Bottom" Height ="400" MinHeight="400" x:Name="BottomGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="18" />
</Grid.RowDefinitions>
<GroupBox Grid.Row="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Some buttons in here-->
<Button Grid.Column="0"/>
<Button Grid.Column="1"/>
</Grid>
<cefSharp:ChromiumWebBrowser x:Name="scefSharpWiki"
Grid.Row="1"
Opacity="{Binding ElementName=opacitySlider, Path=Value}"
Address="https://github.com/cefsharp/CefSharp/wiki"
Title="Scripted"
AllowDrop="True"
WebBrowser="{Binding WebBrowser, Mode=OneWayToSource}">
</cefSharp:ChromiumWebBrowser>
</Grid>
</GroupBox>
<StatusBar Grid.Row="1">
<ProgressBar HorizontalAlignment="Right"
IsIndeterminate="{Binding WebBrowser.IsLoading}"
Width="100"
Height="16"
Margin="3" />
<TextBlock Text="{Binding StatusMessage}" />
<Separator />
<TextBlock Text="{Binding OutputMessage}" />
</StatusBar>
</Grid>
<cefSharp:ChromiumWebBrowser x:Name="browser"
Opacity="{Binding ElementName=opacitySlider, Path=Value}"
Address="{Binding Address, Mode=TwoWay}"
Title="{Binding Title, Mode=OneWayToSource}"
AllowDrop="True"
WebBrowser="{Binding WebBrowser, Mode=OneWayToSource}">
<FrameworkElement.ContextMenu>
<ContextMenu>
<MenuItem Header="Cut" Command="{Binding WebBrowser.CutCommand}"/>
<MenuItem Header="Copy" Command="{Binding WebBrowser.CopyCommand}"/>
<MenuItem Header="Paste" Command="{Binding WebBrowser.PasteCommand}"/>
<MenuItem Header="View Source" Command="{Binding WebBrowser.ViewSourceCommand}" />
<Separator />
<MenuItem Header="Back" Command="{Binding WebBrowser.BackCommand}" />
<MenuItem Header="Forward" Command="{Binding WebBrowser.ForwardCommand}" />
<Separator />
<MenuItem Header="Print ..." Command="{Binding WebBrowser.PrintCommand}" />
<Separator />
<MenuItem Header="Zoom In" Command="{Binding WebBrowser.ZoomInCommand}" />
<MenuItem Header="Zoom Out" Command="{Binding WebBrowser.ZoomOutCommand}" />
<MenuItem Header="Zoom Reset" Command="{Binding WebBrowser.ZoomResetCommand}" />
</ContextMenu>
</FrameworkElement.ContextMenu>
</cefSharp:ChromiumWebBrowser>
</DockPanel>
</UserControl>
@gbucas
Copy link

gbucas commented Jun 26, 2017

Hi WolfieWerewolf

I am a little new to C# and can't get the above to work in VS2017.
Do you perhaps have a complete project/solution "demo" of multiple (or two!) cefSharp controls working on a tabcontrol?
Would REALLY appreciate it if you have...! :)

Thanks
Gerard

@WolfieWerewolf
Copy link
Author

Hi Gerard... sorry I didn't see this until just now. Unfortunately I haven't worked with this code in a very long time; I don't even write C# anymore.... sorry I can't be more helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment