Browse Source

Merge branch 'master' into treeview

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

22
Perspex/Controls/TabControl.cs

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

17
Perspex/Controls/TabStrip.cs

@ -7,6 +7,8 @@
namespace Perspex.Controls namespace Perspex.Controls
{ {
using System; using System;
using System.Collections;
using System.Linq;
using Perspex.Input; using Perspex.Input;
public class TabStrip : SelectingItemsControl public class TabStrip : SelectingItemsControl
@ -22,6 +24,7 @@ namespace Perspex.Controls
public TabStrip() public TabStrip()
{ {
this.PointerPressed += this.OnPointerPressed; this.PointerPressed += this.OnPointerPressed;
this.GetObservable(ItemsProperty).Subscribe(this.ItemsChanged);
this.GetObservable(SelectedItemProperty).Subscribe(this.SelectedItemChanged); this.GetObservable(SelectedItemProperty).Subscribe(this.SelectedItemChanged);
} }
@ -42,6 +45,20 @@ namespace Perspex.Controls
return result; 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) private void OnPointerPressed(object sender, PointerEventArgs e)
{ {
IVisual source = (IVisual)e.Source; IVisual source = (IVisual)e.Source;

Loading…
Cancel
Save