Browse Source

Allow initial selection in TabControl.

pull/4/head
Steven Kirk 12 years ago
parent
commit
d60b06aa02
  1. 22
      Perspex/Controls/TabControl.cs
  2. 17
      Perspex/Controls/TabStrip.cs

22
Perspex/Controls/TabControl.cs

@ -7,7 +7,6 @@
namespace Perspex.Controls
{
using System;
using System.Collections;
using System.Linq;
using System.Reactive.Linq;
@ -20,7 +19,6 @@ namespace Perspex.Controls
public TabControl()
{
this.GetObservable(ItemsProperty).Subscribe(this.ItemsChanged);
this.GetObservable(SelectedItemProperty).Skip(1).Subscribe(this.SelectedItemChanged);
}
@ -32,26 +30,18 @@ namespace Perspex.Controls
if (this.tabStrip != null)
{
this.tabStrip.SelectedItem = this.SelectedItem;
this.tabStrip.GetObservable(TabStrip.SelectedItemProperty).Skip(1).Subscribe(x =>
if (this.IsSet(SelectedItemProperty))
{
this.SelectedItem = SelectedItem;
}
this.tabStrip.GetObservable(TabStrip.SelectedItemProperty).Subscribe(x =>
{
this.SelectedItem = x;
});
}
}
private void ItemsChanged(IEnumerable items)
{
if (items != null)
{
this.SelectedItem = items.OfType<object>().FirstOrDefault();
}
else
{
this.SelectedItem = null;
}
}
private void SelectedItemChanged(object item)
{
this.SelectedItem = item;

17
Perspex/Controls/TabStrip.cs

@ -7,6 +7,8 @@
namespace Perspex.Controls
{
using System;
using System.Collections;
using System.Linq;
using Perspex.Input;
public class TabStrip : SelectingItemsControl
@ -26,6 +28,7 @@ namespace Perspex.Controls
public TabStrip()
{
this.PointerPressed += this.OnPointerPressed;
this.GetObservable(ItemsProperty).Subscribe(this.ItemsChanged);
this.GetObservable(SelectedItemProperty).Subscribe(this.SelectedItemChanged);
}
@ -46,6 +49,20 @@ namespace Perspex.Controls
return result;
}
private void ItemsChanged(IEnumerable items)
{
if (items != null)
{
this.SelectedItem =
items.OfType<TabItem>().FirstOrDefault(x => x.IsSelected) ??
items.OfType<object>().FirstOrDefault();
}
else
{
this.SelectedItem = null;
}
}
private void OnPointerPressed(object sender, PointerEventArgs e)
{
IVisual source = (IVisual)e.Source;

Loading…
Cancel
Save