File tree Expand file tree Collapse file tree 2 files changed +46
-4
lines changed
Expand file tree Collapse file tree 2 files changed +46
-4
lines changed Original file line number Diff line number Diff line change 66 Title =" CefSharp.Wpf.Example"
77 WindowState =" Maximized" >
88
9- <TabControl Margin =" 0,5,0,0" >
10- <!-- TODO: Add support for opening/closing tabs freely, as the user wishes -->
9+ <TabControl x : Name =" TabControl"
10+ Margin =" 0,5,0,0"
11+ SelectionChanged =" OnTabControlSelectionChanged" >
12+ <!-- TODO: Change the TabItems to use a proper ItemsSource-based approach instead. This is just a big hack for now. -->
1113 <TabItem Header =" {Binding Tab1Content.DataContext.Title}"
1214 Width =" 150"
1315 Height =" 20" >
1921 Height =" 20" >
2022 <ContentControl Content =" {Binding Tab2Content}" />
2123 </TabItem >
24+
25+ <TabItem Header =" +" />
2226 </TabControl >
2327</Window >
Original file line number Diff line number Diff line change 1- using CefSharp . Wpf . Example . Views . Main ;
1+ using System . Windows . Data ;
2+ using System . Windows . Input ;
3+ using CefSharp . Wpf . Example . Views . Main ;
24using System . Windows ;
5+ using System . Windows . Controls ;
36
47namespace CefSharp . Wpf . Example
58{
@@ -18,7 +21,42 @@ public MainWindow()
1821 DataContext = new MainViewModel { ShowSidebar = true }
1922 } ;
2023
21- Tab2Content = new MainView
24+ Tab2Content = CreateNewTab ( ) ;
25+ }
26+
27+ private void OnTabControlSelectionChanged ( object sender , SelectionChangedEventArgs e )
28+ {
29+ if ( e . AddedItems . Count != 1 ) return ;
30+
31+ var selectedtab = ( TabItem ) e . AddedItems [ 0 ] ;
32+ if ( ( string ) selectedtab . Header != "+" )
33+ {
34+ return ;
35+ }
36+
37+ var tabItem = CreateTabItem ( ) ;
38+ TabControl . Items . Insert ( TabControl . Items . Count - 1 , tabItem ) ;
39+ }
40+
41+ private static TabItem CreateTabItem ( )
42+ {
43+ var tabItem = new TabItem
44+ {
45+ Width = 150 ,
46+ Height = 20 ,
47+ IsSelected = true ,
48+ Content = CreateNewTab ( )
49+ } ;
50+ tabItem . SetBinding ( HeaderedContentControl . HeaderProperty , new Binding ( "Content.DataContext.Title" )
51+ {
52+ RelativeSource = RelativeSource . Self
53+ } ) ;
54+ return tabItem ;
55+ }
56+
57+ private static MainView CreateNewTab ( )
58+ {
59+ return new MainView
2260 {
2361 DataContext = new MainViewModel ( "http://www.google.com" )
2462 } ;
You can’t perform that action at this time.
0 commit comments