diff --git a/Library/Behaviors/ActionCollection.cs b/Library/Behaviors/ActionCollection.cs deleted file mode 100755 index b9af3bb..0000000 --- a/Library/Behaviors/ActionCollection.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Specialized; -using Xamarin.Forms; - -namespace Behaviors -{ - [Preserve(AllMembers = true)] - public class ActionCollection : BindableObjectCollection - { - public ActionCollection() - { - CollectionChanged += ActionCollection_CollectionChanged; - } - - void ActionCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - var collectionChange = e.Action; - - if (collectionChange == NotifyCollectionChangedAction.Reset) - { - foreach (BindableObject bindable in this) - { - ActionCollection.VerifyType(bindable); - } - } - else if (collectionChange == NotifyCollectionChangedAction.Replace) - { - BindableObject changed = this[(int)e.NewStartingIndex]; - ActionCollection.VerifyType(changed); - } - } - - static void VerifyType(BindableObject bindable) - { - if (!(bindable is IAction)) - { - throw new InvalidOperationException("Non-IAction added to IAction collection"); - } - } - } -} - diff --git a/Library/Behaviors/BehaviorPropertiesBase.cs b/Library/Behaviors/BehaviorPropertiesBase.cs index 089042d..629b2d8 100644 --- a/Library/Behaviors/BehaviorPropertiesBase.cs +++ b/Library/Behaviors/BehaviorPropertiesBase.cs @@ -1,4 +1,5 @@ -using Xamarin.Forms; +using System.Collections.ObjectModel; +using Xamarin.Forms; namespace Behaviors { @@ -6,19 +7,19 @@ namespace Behaviors [ContentProperty("Actions")] public class BehaviorPropertiesBase : BehaviorBase { - public static readonly BindableProperty ActionsProperty = BindableProperty.Create(nameof(Actions), typeof(ActionCollection), typeof(BehaviorPropertiesBase), null); + public static readonly BindableProperty ActionsProperty = BindableProperty.Create(nameof(Actions), typeof(ObservableCollection), typeof(BehaviorPropertiesBase), null); - public ActionCollection Actions + public ObservableCollection Actions { get { - return (ActionCollection)GetValue(ActionsProperty); + return (ObservableCollection)GetValue(ActionsProperty); } } public BehaviorPropertiesBase() { - SetValue(ActionsProperty, new ActionCollection()); + SetValue(ActionsProperty, new ObservableCollection()); } } } diff --git a/Library/Behaviors/Behaviors.csproj b/Library/Behaviors/Behaviors.csproj index 2662832..43e87a8 100644 --- a/Library/Behaviors/Behaviors.csproj +++ b/Library/Behaviors/Behaviors.csproj @@ -2,7 +2,7 @@ netstandard1.0 Behaviors.Forms - 1.4.0 + 1.4.1 David Britch Using behaviors and actions, developers can create a variety of scenarios in XAML that previously required C#. diff --git a/Library/Behaviors/BindableObjectCollection.cs b/Library/Behaviors/BindableObjectCollection.cs deleted file mode 100755 index ef8e695..0000000 --- a/Library/Behaviors/BindableObjectCollection.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using Xamarin.Forms; - -namespace Behaviors -{ - [Preserve(AllMembers = true)] - public class BindableObjectCollection : BindableObject, IEnumerable, INotifyCollectionChanged - { - List Items = new List(); - - public event NotifyCollectionChangedEventHandler CollectionChanged; - - public int IndexOf(BindableObject item) - { - return Items.IndexOf(item); - } - - public void Insert(int index, BindableObject item) - { - Items.Insert(index, item); - CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); - } - - public void RemoveAt(int index) - { - var oldItem = this[index]; - Items.RemoveAt(index); - CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldItem, index)); - } - - public BindableObject this[int index] - { - get - { - return this[index]; - } - set - { - var oldItem = this[index]; - this[index] = (BindableObject)value; - CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, value, oldItem)); - } - } - - public void Add(BindableObject item) - { - Items.Add(item); - CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, Count - 1)); - } - - public void Clear() - { - Items.Clear(); - CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); - } - - public bool Contains(BindableObject item) - { - return Items.Contains(item); - } - - public void CopyTo(BindableObject[] array, int arrayIndex) - { - Items.CopyTo(array, arrayIndex); - } - - public bool Remove(BindableObject item) - { - var oldIndex = IndexOf(item); - if (Items.Remove(item)) - { - CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, oldIndex)); - return true; - } - return false; - } - - public int Count - { - get - { - return Items.Count; - } - } - - public bool IsReadOnly - { - get - { - return false; - } - } - - public IEnumerator GetEnumerator() - { - return Items.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} -