// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Controls { using System; using System.Linq; using System.Reactive.Linq; using Perspex.Collections; using Perspex.Controls.Generators; using Perspex.Controls.Presenters; using Perspex.Controls.Primitives; public class TabControl : SelectingItemsControl { public static readonly PerspexProperty SelectedContentProperty = PerspexProperty.Register("SelectedContent"); public static readonly PerspexProperty SelectedTabProperty = PerspexProperty.Register("SelectedTab"); private SingleItemPerspexList logicalChild = new SingleItemPerspexList(); public TabControl() { this.GetObservable(SelectedItemProperty).Subscribe(x => { ContentControl c = x as ContentControl; object content = (c != null) ? c.Content : null; this.SetValue(SelectedContentProperty, content); }); this.BindTwoWay(SelectedTabProperty, this, SelectingItemsControl.SelectedItemProperty); } public object SelectedContent { get { return this.GetValue(SelectedContentProperty); } set { this.SetValue(SelectedContentProperty, value); } } public TabItem SelectedTab { get { return this.GetValue(SelectedTabProperty); } set { this.SetValue(SelectedTabProperty, value); } } protected override ItemContainerGenerator CreateItemContainerGenerator() { return new TypedItemContainerGenerator(this); } } }