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 class SwipeItems : Element, IList<ISwipeItem>, INotifyCollectionChanged
12 readonly ObservableCollection<ISwipeItem> _swipeItems;
14 public SwipeItems(IEnumerable<ISwipeItem> swipeItems)
16 _swipeItems = new ObservableCollection<ISwipeItem>(swipeItems) ?? throw new ArgumentNullException(nameof(swipeItems));
17 _swipeItems.CollectionChanged += OnSwipeItemsChanged;
20 public SwipeItems() : this(Enumerable.Empty<ISwipeItem>())
25 public static readonly BindableProperty ModeProperty = BindableProperty.Create(nameof(Mode), typeof(SwipeMode), typeof(SwipeItems), SwipeMode.Reveal);
26 public static readonly BindableProperty SwipeBehaviorOnInvokedProperty = BindableProperty.Create(nameof(SwipeBehaviorOnInvoked), typeof(SwipeBehaviorOnInvoked), typeof(SwipeItems), SwipeBehaviorOnInvoked.Auto);
30 get { return (SwipeMode)GetValue(ModeProperty); }
31 set { SetValue(ModeProperty, value); }
34 public SwipeBehaviorOnInvoked SwipeBehaviorOnInvoked
36 get { return (SwipeBehaviorOnInvoked)GetValue(SwipeBehaviorOnInvokedProperty); }
37 set { SetValue(SwipeBehaviorOnInvokedProperty, value); }
40 public event NotifyCollectionChangedEventHandler CollectionChanged
42 add { _swipeItems.CollectionChanged += value; }
43 remove { _swipeItems.CollectionChanged -= value; }
46 public ISwipeItem this[int index]
48 get => _swipeItems.Count > index ? _swipeItems[index] : null;
49 set => _swipeItems[index] = value;
52 public int Count => _swipeItems.Count;
54 public bool IsReadOnly => false;
56 public void Add(ISwipeItem item)
58 _swipeItems.Add(item);
66 public bool Contains(ISwipeItem item)
68 return _swipeItems.Contains(item);
71 public void CopyTo(ISwipeItem[] array, int arrayIndex)
73 _swipeItems.CopyTo(array, arrayIndex);
76 public IEnumerator<ISwipeItem> GetEnumerator()
78 return _swipeItems.GetEnumerator();
81 public int IndexOf(ISwipeItem item)
83 return _swipeItems.IndexOf(item);
86 public void Insert(int index, ISwipeItem item)
88 _swipeItems.Insert(index, item);
91 public bool Remove(ISwipeItem item)
93 return _swipeItems.Remove(item);
96 public void RemoveAt(int index)
98 _swipeItems.RemoveAt(index);
101 protected override void OnBindingContextChanged()
103 base.OnBindingContextChanged();
105 object bc = BindingContext;
107 foreach (BindableObject item in _swipeItems)
108 SetInheritedBindingContext(item, bc);
111 void OnSwipeItemsChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
113 if (notifyCollectionChangedEventArgs.NewItems == null)
116 object bc = BindingContext;
118 foreach (BindableObject item in notifyCollectionChangedEventArgs.NewItems)
119 SetInheritedBindingContext(item, bc);
122 IEnumerator IEnumerable.GetEnumerator()
124 return _swipeItems.GetEnumerator();