diff --git a/Perspex.Base/Collections/PerspexReadOnlyListView.cs b/Perspex.Base/Collections/PerspexReadOnlyListView.cs index b12e52efbb..918fd6e885 100644 --- a/Perspex.Base/Collections/PerspexReadOnlyListView.cs +++ b/Perspex.Base/Collections/PerspexReadOnlyListView.cs @@ -13,134 +13,6 @@ namespace Perspex.Collections using System.ComponentModel; using System.Linq; - public class PerspexReadOnlyListView : IPerspexReadOnlyList, IDisposable - { - private IPerspexReadOnlyList source; - - public PerspexReadOnlyListView() - : this(null) - { - } - - public PerspexReadOnlyListView(IPerspexReadOnlyList 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 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 GetEnumerator() - { - return (this.source != null) ? - this.source.GetEnumerator() : - Enumerable.Empty().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 : IPerspexReadOnlyList, IDisposable { private IPerspexReadOnlyList source; diff --git a/Perspex.Controls/ContentControl.cs b/Perspex.Controls/ContentControl.cs index aa0bfd803f..84c327a36b 100644 --- a/Perspex.Controls/ContentControl.cs +++ b/Perspex.Controls/ContentControl.cs @@ -24,7 +24,7 @@ namespace Perspex.Controls public static readonly PerspexProperty VerticalContentAlignmentProperty = PerspexProperty.Register("VerticalContentAlignment"); - private PerspexReadOnlyListView logicalChildren = new PerspexReadOnlyListView(); + private IPerspexReadOnlyList logicalChildren = new PerspexList(); public ContentControl() { @@ -63,11 +63,7 @@ namespace Perspex.Controls if (presenter != null) { - this.logicalChildren.Source = ((ILogical)presenter).LogicalChildren; - } - else - { - this.logicalChildren.Source = null; + this.logicalChildren = ((ILogical)presenter)?.LogicalChildren; } } diff --git a/Perspex.Controls/DropDown.cs b/Perspex.Controls/DropDown.cs index ee1a03f1a3..f20409ac8a 100644 --- a/Perspex.Controls/DropDown.cs +++ b/Perspex.Controls/DropDown.cs @@ -28,7 +28,7 @@ namespace Perspex.Controls public static readonly PerspexProperty IsDropDownOpenProperty = PerspexProperty.Register("IsDropDownOpen"); - private PerspexReadOnlyListView logicalChildren = new PerspexReadOnlyListView(); + private IPerspexReadOnlyList logicalChildren = new PerspexSingleItemList(); public DropDown() { @@ -77,7 +77,7 @@ namespace Perspex.Controls { var container = this.GetTemplateChild("container"); ((IItemsPanel)container).ChildLogicalParent = this; - this.logicalChildren.Source = ((ILogical)container).LogicalChildren; + this.logicalChildren = ((ILogical)container).LogicalChildren; } private void SetContentParent(Tuple change) diff --git a/Perspex.Controls/TabControl.cs b/Perspex.Controls/TabControl.cs index e0e7b1bd4d..4f6654f966 100644 --- a/Perspex.Controls/TabControl.cs +++ b/Perspex.Controls/TabControl.cs @@ -25,8 +25,7 @@ namespace Perspex.Controls public static readonly PerspexProperty TransitionProperty = Deck.TransitionProperty.AddOwner(); - private PerspexReadOnlyListView logicalChildren = - new PerspexReadOnlyListView(); + private IPerspexReadOnlyList logicalChildren = new PerspexSingleItemList(); static TabControl() { @@ -81,7 +80,7 @@ namespace Perspex.Controls base.OnTemplateApplied(); this.deck = this.GetTemplateChild("deck"); - this.logicalChildren.Source = ((ILogical)deck).LogicalChildren; + this.logicalChildren = ((ILogical)deck).LogicalChildren; } } }