2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Collections.ObjectModel;
5 using System.Collections.Specialized;
8 namespace Xamarin.Forms
10 public enum OpenSwipeItem
18 public class SwipeItems : Element, IList<ISwipeItem>, INotifyCollectionChanged
20 readonly ObservableCollection<ISwipeItem> _swipeItems;
22 public SwipeItems(IEnumerable<ISwipeItem> swipeItems)
24 _swipeItems = new ObservableCollection<ISwipeItem>(swipeItems) ?? throw new ArgumentNullException(nameof(swipeItems));
25 _swipeItems.CollectionChanged += OnSwipeItemsChanged;
28 public SwipeItems() : this(Enumerable.Empty<ISwipeItem>())
33 public static readonly BindableProperty ModeProperty = BindableProperty.Create(nameof(Mode), typeof(SwipeMode), typeof(SwipeItems), SwipeMode.Reveal);
34 public static readonly BindableProperty SwipeBehaviorOnInvokedProperty = BindableProperty.Create(nameof(SwipeBehaviorOnInvoked), typeof(SwipeBehaviorOnInvoked), typeof(SwipeItems), SwipeBehaviorOnInvoked.Auto);
38 get { return (SwipeMode)GetValue(ModeProperty); }
39 set { SetValue(ModeProperty, value); }
42 public SwipeBehaviorOnInvoked SwipeBehaviorOnInvoked
44 get { return (SwipeBehaviorOnInvoked)GetValue(SwipeBehaviorOnInvokedProperty); }
45 set { SetValue(SwipeBehaviorOnInvokedProperty, value); }
48 public event NotifyCollectionChangedEventHandler CollectionChanged
50 add { _swipeItems.CollectionChanged += value; }
51 remove { _swipeItems.CollectionChanged -= value; }
54 public ISwipeItem this[int index]
56 get => _swipeItems.Count > index ? _swipeItems[index] : null;
57 set => _swipeItems[index] = value;
60 public int Count => _swipeItems.Count;
62 public bool IsReadOnly => false;
64 public void Add(ISwipeItem item)
66 _swipeItems.Add(item);
74 public bool Contains(ISwipeItem item)
76 return _swipeItems.Contains(item);
79 public void CopyTo(ISwipeItem[] array, int arrayIndex)
81 _swipeItems.CopyTo(array, arrayIndex);
84 public IEnumerator<ISwipeItem> GetEnumerator()
86 return _swipeItems.GetEnumerator();
89 public int IndexOf(ISwipeItem item)
91 return _swipeItems.IndexOf(item);
94 public void Insert(int index, ISwipeItem item)
96 _swipeItems.Insert(index, item);
99 public bool Remove(ISwipeItem item)
101 return _swipeItems.Remove(item);
104 public void RemoveAt(int index)
106 _swipeItems.RemoveAt(index);
109 protected override void OnBindingContextChanged()
111 base.OnBindingContextChanged();
113 object bc = BindingContext;
115 foreach (BindableObject item in _swipeItems)
116 SetInheritedBindingContext(item, bc);
119 void OnSwipeItemsChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
121 if (notifyCollectionChangedEventArgs.NewItems == null)
124 object bc = BindingContext;
126 foreach (BindableObject item in notifyCollectionChangedEventArgs.NewItems)
127 SetInheritedBindingContext(item, bc);
130 IEnumerator IEnumerable.GetEnumerator()
132 return _swipeItems.GetEnumerator();