Permalink
Browse files

Get z-index and tab-index values correct for tabs. Added title input for

main window.
  • Loading branch information...
Curtis Schlak
Curtis Schlak committed Jun 29, 2012
1 parent a5d092b commit c6eb3a05bd6dab96e500a9f965091ee75588e075
@@ -69,6 +69,7 @@ protected override void OnInitialized(EventArgs e)
{
this.SelectedIndex = 0;
}
KeyboardNavigation.SetIsTabStop(this, false);
}
public object SelectedContent
@@ -194,7 +195,8 @@ protected override void PrepareContainerForItemOverride(DependencyObject element
base.PrepareContainerForItemOverride(element, item);
if (element != item)
{
ObjectToContainer[item] = element;
this.ObjectToContainer[item] = element;
this.SetChildrenZ();
}
}
@@ -139,6 +139,18 @@ protected override Size MeasureOverride(Size availableSize)
return resultSize;
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
this.SetTabItemsOnTabs();
}
protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
{
base.OnVisualChildrenChanged(visualAdded, visualRemoved);
this.SetTabItemsOnTabs();
}
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseLeftButtonDown(e);
@@ -250,6 +262,19 @@ private ChromeTabControl ParentTabControl
}
}
private void SetTabItemsOnTabs()
{
for(int i = 0; i < this.Children.Count; i += 1)
{
DependencyObject depObj = this.Children[i] as DependencyObject;
ChromeTabItem item = ItemsControl.ContainerFromElement(this.ParentTabControl, depObj) as ChromeTabItem;
if(item != null)
{
KeyboardNavigation.SetTabIndex(item, i);
}
}
}
private Size finalSize;
private double overlap;
private double leftMargin;
@@ -7,6 +7,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<my:ChromeTabControl Name="chrometabs">
<my:ChromeTabItem Header="One" Background="Orange">
@@ -18,15 +19,19 @@
<my:ChromeTabItem Header="Three" Background="Green">
<Label>Tres</Label>
</my:ChromeTabItem>
<Button>Hello</Button>
<my:ChromeTabItem Header="Four" Background="Green">
<Label>Quattro</Label>
</my:ChromeTabItem>
<Button>Hello</Button>
</my:ChromeTabControl>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Click="HandleRemoveTab" Margin="2">Close Selected Tab</Button>
<Button Click="HandleAddTab" Margin="2" IsEnabled="{Binding Path=CanAddTab, ElementName=chrometabs}">Add Tab</Button>
<Button Click="HandleAddTabAndSelect" Margin="2" IsEnabled="{Binding Path=CanAddTab, ElementName=chrometabs}">Add Tab And Select</Button>
</StackPanel>
<DockPanel LastChildFill="True" Grid.Row="2">
<Label DockPanel.Dock="Left">Title</Label>
<TextBox Name="title"></TextBox>
</DockPanel>
</Grid>
</Window>
@@ -11,6 +11,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
namespace ChromiumTabsRunner
{
@@ -22,21 +23,39 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
this.newTabNumber = 1;
}
private void HandleAddTab(object sender, RoutedEventArgs e)
{
this.chrometabs.AddTab(new Button { Content = "MOO!" }, false);
this.chrometabs.AddTab(this.GenerateNewItem(), false);
}
private void HandleAddTabAndSelect(object sender, RoutedEventArgs e)
{
this.chrometabs.AddTab(new Button { Content = "MOO!" }, true);
this.chrometabs.AddTab(this.GenerateNewItem(), true);
}
private object GenerateNewItem()
{
object itemToAdd = new Button { Content = "Moo " + this.newTabNumber };
Interlocked.Increment(ref this.newTabNumber);
if(this.title.Text.Length > 0)
{
itemToAdd = new ChromeTabs.ChromeTabItem
{
Header = this.title.Text,
Content = itemToAdd
};
}
return itemToAdd;
}
private void HandleRemoveTab(object sender, RoutedEventArgs e)
{
this.chrometabs.RemoveTab(this.chrometabs.SelectedItem);
}
private int newTabNumber;
}
}

0 comments on commit c6eb3a0

Please sign in to comment.