// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Controls { using Perspex.Animation; using Perspex.Controls.Presenters; using Perspex.Controls.Primitives; /// /// A tab control that displays a tab strip along with the content of the selected tab. /// public class TabControl : SelectingItemsControl, IReparentingHost { /// /// Defines the property. /// public static readonly PerspexProperty SelectedTabProperty = PerspexProperty.Register("SelectedTab"); /// /// Defines the property. /// public static readonly PerspexProperty TransitionProperty = Deck.TransitionProperty.AddOwner(); /// /// Initializes static members of the class. /// static TabControl() { AutoSelectProperty.OverrideDefaultValue(true); FocusableProperty.OverrideDefaultValue(false); SelectedIndexProperty.Changed.AddClassHandler(x => x.SelectedIndexChanged); } /// /// Gets the as a . /// public TabItem SelectedTab { get { return this.GetValue(SelectedTabProperty); } private set { this.SetValue(SelectedTabProperty, value); } } /// /// Gets or sets the transition to use when switching tabs. /// public IPageTransition Transition { get { return this.GetValue(TransitionProperty); } set { this.SetValue(TransitionProperty, value); } } /// /// Asks the control whether it wants to reparent the logical children of the specified /// control. /// /// The control. /// /// True if the control wants to reparent its logical children otherwise false. /// bool IReparentingHost.WillReparentChildrenOf(IControl control) { return control is DeckPresenter; } /// /// Called when the property changes. /// /// The event args. private void SelectedIndexChanged(PerspexPropertyChangedEventArgs e) { if ((int)e.NewValue != -1) { var item = this.SelectedItem as IContentControl; var content = item?.Content ?? item; this.SelectedTab = item as TabItem; } } } }