Browse Source

Revert "Removed PerspexReadOnlyListView<T>"

This reverts commit 0359f8c9a3.
pull/58/head
Steven Kirk 11 years ago
parent
commit
3aa621cd96
  1. 128
      Perspex.Base/Collections/PerspexReadOnlyListView.cs
  2. 8
      Perspex.Controls/ContentControl.cs
  3. 4
      Perspex.Controls/DropDown.cs
  4. 5
      Perspex.Controls/TabControl.cs

128
Perspex.Base/Collections/PerspexReadOnlyListView.cs

@ -13,6 +13,134 @@ namespace Perspex.Collections
using System.ComponentModel;
using System.Linq;
public class PerspexReadOnlyListView<T> : IPerspexReadOnlyList<T>, IDisposable
{
private IPerspexReadOnlyList<T> source;
public PerspexReadOnlyListView()
: this(null)
{
}
public PerspexReadOnlyListView(IPerspexReadOnlyList<T> source)
{
this.source = source;
if (source != null)
{
this.source.CollectionChanged += this.SourceCollectionChanged;
}
}
public event NotifyCollectionChangedEventHandler CollectionChanged;
public event PropertyChangedEventHandler PropertyChanged;
public int Count
{
get { return this.source?.Count ?? 0; }
}
public IPerspexReadOnlyList<T> Source
{
get
{
return this.source;
}
set
{
if (this.source != null)
{
this.source.CollectionChanged -= this.SourceCollectionChanged;
if (this.CollectionChanged != null)
{
var ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Remove,
this.source,
0);
this.CollectionChanged(this, ev);
}
}
this.source = value;
if (this.source != null)
{
this.source.CollectionChanged += this.SourceCollectionChanged;
if (this.CollectionChanged != null)
{
var ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Add,
this.source.ToList(),
0);
this.CollectionChanged(this, ev);
}
}
}
}
public T this[int index]
{
get { return this.source[index]; }
}
public void Dispose()
{
this.source.CollectionChanged -= this.SourceCollectionChanged;
}
public IEnumerator<T> GetEnumerator()
{
return (this.source != null) ?
this.source.GetEnumerator() :
Enumerable.Empty<T>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
private void SourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (this.CollectionChanged != null)
{
NotifyCollectionChangedEventArgs ev;
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Add,
e.NewItems,
e.NewStartingIndex);
break;
case NotifyCollectionChangedAction.Remove:
ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Remove,
e.OldItems,
e.OldStartingIndex);
break;
case NotifyCollectionChangedAction.Replace:
ev = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Replace,
e.NewItems,
e.OldItems,
e.OldStartingIndex);
break;
default:
throw new NotSupportedException("Action not yet implemented.");
}
this.CollectionChanged(this, ev);
}
}
}
public class PerspexReadOnlyListView<TIn, TOut> : IPerspexReadOnlyList<TOut>, IDisposable
{
private IPerspexReadOnlyList<TIn> source;

8
Perspex.Controls/ContentControl.cs

@ -24,7 +24,7 @@ namespace Perspex.Controls
public static readonly PerspexProperty<VerticalAlignment> VerticalContentAlignmentProperty =
PerspexProperty.Register<ContentControl, VerticalAlignment>("VerticalContentAlignment");
private IPerspexReadOnlyList<ILogical> logicalChildren = new PerspexList<ILogical>();
private PerspexReadOnlyListView<ILogical> logicalChildren = new PerspexReadOnlyListView<ILogical>();
public ContentControl()
{
@ -63,7 +63,11 @@ namespace Perspex.Controls
if (presenter != null)
{
this.logicalChildren = ((ILogical)presenter)?.LogicalChildren;
this.logicalChildren.Source = ((ILogical)presenter).LogicalChildren;
}
else
{
this.logicalChildren.Source = null;
}
}

4
Perspex.Controls/DropDown.cs

@ -28,7 +28,7 @@ namespace Perspex.Controls
public static readonly PerspexProperty<bool> IsDropDownOpenProperty =
PerspexProperty.Register<DropDown, bool>("IsDropDownOpen");
private IPerspexReadOnlyList<ILogical> logicalChildren = new PerspexSingleItemList<ILogical>();
private PerspexReadOnlyListView<ILogical> logicalChildren = new PerspexReadOnlyListView<ILogical>();
public DropDown()
{
@ -77,7 +77,7 @@ namespace Perspex.Controls
{
var container = this.GetTemplateChild<Panel>("container");
((IItemsPanel)container).ChildLogicalParent = this;
this.logicalChildren = ((ILogical)container).LogicalChildren;
this.logicalChildren.Source = ((ILogical)container).LogicalChildren;
}
private void SetContentParent(Tuple<object, object> change)

5
Perspex.Controls/TabControl.cs

@ -25,7 +25,8 @@ namespace Perspex.Controls
public static readonly PerspexProperty<IPageTransition> TransitionProperty =
Deck.TransitionProperty.AddOwner<TabControl>();
private IPerspexReadOnlyList<ILogical> logicalChildren = new PerspexSingleItemList<ILogical>();
private PerspexReadOnlyListView<ILogical> logicalChildren =
new PerspexReadOnlyListView<ILogical>();
static TabControl()
{
@ -80,7 +81,7 @@ namespace Perspex.Controls
base.OnTemplateApplied();
this.deck = this.GetTemplateChild<Deck>("deck");
this.logicalChildren = ((ILogical)deck).LogicalChildren;
this.logicalChildren.Source = ((ILogical)deck).LogicalChildren;
}
}
}

Loading…
Cancel
Save