Add very basic Tabbed Window

Can be used to reproduce issue #18
This commit is contained in:
Alex Maitland
2022-09-07 13:40:08 +10:00
parent 6e3ca280ee
commit 756ce3012a
3 changed files with 55 additions and 1 deletions
@@ -9,7 +9,7 @@
xmlns:hwndhost="clr-namespace:CefSharp.Wpf.HwndHost;assembly=CefSharp.Wpf.HwndHost"
FocusManager.FocusedElement="{Binding ElementName=Browser}"
mc:Ignorable="d"
Title="MainWindow" Height="768" Width="1024">
Title="CefSharp.Wpf.HwndHost.Example - MainWindow" Height="768" Width="1024">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@@ -0,0 +1,13 @@
<Window x:Class="CefSharp.Wpf.HwndHost.Example.TabbedMainWindow"
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"
mc:Ignorable="d"
Title="CefSharp.Wpf.HwndHost.Example - TabbedMainWindow" Height="450" Width="800">
<Grid>
<Button Height="20" VerticalAlignment="Top" Content="New tab" Click="OnNewTabButtonClick"/>
<Button Height="20" Margin="0,20,0,0" VerticalAlignment="Top" Content="Close current tab" Click="OnCloseTabButtonClick"/>
<TabControl x:Name="Tabs" Margin="0,40,0,0"/>
</Grid>
</Window>
@@ -0,0 +1,41 @@
using System.Windows;
using System.Windows.Controls;
namespace CefSharp.Wpf.HwndHost.Example
{
/// <summary>
/// Interaction logic for TabbedMainWindow.xaml
/// </summary>
public partial class TabbedMainWindow : Window
{
public TabbedMainWindow()
{
InitializeComponent();
NewTab();
NewTab();
NewTab();
}
private void NewTab()
{
var browser = new ChromiumWebBrowser("https://example.com/");
browser.Address = "https://example.com/";
Tabs.Items.Add(new TabItem { Header = "Tab", Content = browser });
}
private void OnNewTabButtonClick(object sender, RoutedEventArgs e)
{
NewTab();
}
private void OnCloseTabButtonClick(object sender, RoutedEventArgs e)
{
var Tab = (TabItem)Tabs.Items[Tabs.SelectedIndex];
var browser = (ChromiumWebBrowser)Tab.Content;
Tab.Content = null;
browser.Dispose();
Tabs.Items.Remove(Tab);
}
}
}