|
|
@ -11,9 +11,10 @@ namespace Perspex.Controls |
|
|
using System.Reactive.Linq; |
|
|
using System.Reactive.Linq; |
|
|
using Perspex.Collections; |
|
|
using Perspex.Collections; |
|
|
using Perspex.Controls.Generators; |
|
|
using Perspex.Controls.Generators; |
|
|
|
|
|
using Perspex.Controls.Presenters; |
|
|
using Perspex.Controls.Primitives; |
|
|
using Perspex.Controls.Primitives; |
|
|
|
|
|
|
|
|
public class TabControl : SelectingItemsControl |
|
|
public class TabControl : SelectingItemsControl, ILogical |
|
|
{ |
|
|
{ |
|
|
public static readonly PerspexProperty<object> SelectedContentProperty = |
|
|
public static readonly PerspexProperty<object> SelectedContentProperty = |
|
|
PerspexProperty.Register<TabControl, object>("SelectedContent"); |
|
|
PerspexProperty.Register<TabControl, object>("SelectedContent"); |
|
|
@ -23,6 +24,12 @@ namespace Perspex.Controls |
|
|
|
|
|
|
|
|
private TabStrip tabStrip; |
|
|
private TabStrip tabStrip; |
|
|
|
|
|
|
|
|
|
|
|
private ContentPresenter presenter; |
|
|
|
|
|
|
|
|
|
|
|
private IDisposable presenterSubscription; |
|
|
|
|
|
|
|
|
|
|
|
private SingleItemPerspexList<ILogical> logicalChild = new SingleItemPerspexList<ILogical>(); |
|
|
|
|
|
|
|
|
public TabControl() |
|
|
public TabControl() |
|
|
{ |
|
|
{ |
|
|
this.GetObservable(SelectedItemProperty).Subscribe(x => |
|
|
this.GetObservable(SelectedItemProperty).Subscribe(x => |
|
|
@ -49,6 +56,11 @@ namespace Perspex.Controls |
|
|
private set { this.SetValue(SelectedTabProperty, value); } |
|
|
private set { this.SetValue(SelectedTabProperty, value); } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IReadOnlyPerspexList<ILogical> ILogical.LogicalChildren |
|
|
|
|
|
{ |
|
|
|
|
|
get { return this.logicalChild; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected override ItemContainerGenerator CreateItemContainerGenerator() |
|
|
protected override ItemContainerGenerator CreateItemContainerGenerator() |
|
|
{ |
|
|
{ |
|
|
return new TypedItemContainerGenerator<TabItem>(this); |
|
|
return new TypedItemContainerGenerator<TabItem>(this); |
|
|
@ -56,7 +68,20 @@ namespace Perspex.Controls |
|
|
|
|
|
|
|
|
protected override void OnTemplateApplied() |
|
|
protected override void OnTemplateApplied() |
|
|
{ |
|
|
{ |
|
|
base.OnTemplateApplied(); |
|
|
if (this.presenterSubscription != null) |
|
|
|
|
|
{ |
|
|
|
|
|
this.presenterSubscription.Dispose(); |
|
|
|
|
|
this.presenterSubscription = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.presenter = this.FindTemplateChild<ContentPresenter>("contentPresenter"); |
|
|
|
|
|
|
|
|
|
|
|
if (this.presenter != null) |
|
|
|
|
|
{ |
|
|
|
|
|
this.presenterSubscription = this.presenter.ChildObservable |
|
|
|
|
|
.Subscribe(x => this.logicalChild.SingleItem = x); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.tabStrip = this.GetTemplateControls().OfType<TabStrip>().FirstOrDefault(); |
|
|
this.tabStrip = this.GetTemplateControls().OfType<TabStrip>().FirstOrDefault(); |
|
|
this.BindTwoWay(TabControl.SelectedItemProperty, this.tabStrip, TabControl.SelectedItemProperty); |
|
|
this.BindTwoWay(TabControl.SelectedItemProperty, this.tabStrip, TabControl.SelectedItemProperty); |
|
|
} |
|
|
} |
|
|
|