diff --git a/Perspex/Controls/TabItem.cs b/Perspex/Controls/TabItem.cs index dc64b8d78b..351f4f2941 100644 --- a/Perspex/Controls/TabItem.cs +++ b/Perspex/Controls/TabItem.cs @@ -8,8 +8,19 @@ namespace Perspex.Controls { public class TabItem : HeaderedContentControl { + public static readonly PerspexProperty IsSelectedProperty = + PerspexProperty.Register("IsSelected"); + public TabItem() { + this.AddPseudoClass(IsSelectedProperty, ":selected"); + AffectsRender(IsSelectedProperty); + } + + public bool IsSelected + { + get { return this.GetValue(IsSelectedProperty); } + set { this.SetValue(IsSelectedProperty, value); } } } } diff --git a/Perspex/Controls/TabStrip.cs b/Perspex/Controls/TabStrip.cs index cd5b691c19..12386f0ec9 100644 --- a/Perspex/Controls/TabStrip.cs +++ b/Perspex/Controls/TabStrip.cs @@ -4,12 +4,10 @@ // // ----------------------------------------------------------------------- +using Perspex.Input; + namespace Perspex.Controls { - using System; - using System.Collections.Generic; - using System.Linq; - public class TabStrip : ItemsControl { private static readonly ItemsPanelTemplate PanelTemplate = new ItemsPanelTemplate( @@ -23,5 +21,31 @@ namespace Perspex.Controls ItemsPanelProperty.OverrideDefaultValue(typeof(TabStrip), PanelTemplate); ItemTemplateProperty.OverrideDefaultValue(typeof(TabStrip), TabTemplate); } + + public TabStrip() + { + this.PointerPressed += this.OnPointerPressed; + } + + private void OnPointerPressed(object sender, PointerEventArgs e) + { + IVisual source = (IVisual)e.Source; + ContentPresenter presenter = source.GetVisualAncestor(); + + if (presenter != null) + { + TabItem item = presenter.TemplatedParent as TabItem; + + if (item != null && item.TemplatedParent == this) + { + item.IsSelected = true; + + foreach (var i in item.GetVisualSiblings()) + { + i.IsSelected = false; + } + } + } + } } } diff --git a/Perspex/VisualExtensions.cs b/Perspex/VisualExtensions.cs index 427adf2e4f..34988704e3 100644 --- a/Perspex/VisualExtensions.cs +++ b/Perspex/VisualExtensions.cs @@ -124,5 +124,21 @@ namespace Perspex } } } + + public static IEnumerable GetVisualSiblings(this IVisual visual) + { + IVisual parent = visual.VisualParent; + + if (parent != null) + { + foreach (T sibling in parent.VisualChildren.OfType()) + { + if ((IVisual)sibling != visual) + { + yield return sibling; + } + } + } + } } } diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index f1eca4227c..59cf8b57c2 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -77,6 +77,7 @@ namespace TestApplication new TabItem { Header = "Tab 1", + IsSelected = true, }, new TabItem {