using System.Collections; using System.ComponentModel; using Xamarin.Forms.Internals; namespace Xamarin.Forms { public abstract class ItemsView : View, ITemplatedItemsView where TVisual : BindableObject { /* public static readonly BindableProperty InfiniteScrollingProperty = BindableProperty.Create (lv => lv.InfiniteScrolling, false); public bool InfiniteScrolling { get { return (bool) GetValue (InfiniteScrollingProperty); } set { SetValue (InfiniteScrollingProperty, value); } }*/ public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable), typeof(ItemsView), null, propertyChanged: OnItemsSourceChanged); public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(ItemsView), null, validateValue: (b, v) => ((ItemsView)b).ValidateItemTemplate((DataTemplate)v)); internal ItemsView() => TemplatedItems = new TemplatedItemsList, TVisual>(this, ItemsSourceProperty, ItemTemplateProperty); public IEnumerable ItemsSource { get => (IEnumerable)GetValue(ItemsSourceProperty); set => SetValue(ItemsSourceProperty, value); } public DataTemplate ItemTemplate { get => (DataTemplate)GetValue(ItemTemplateProperty); set => SetValue(ItemTemplateProperty, value); } /*public void UpdateNonNotifyingList() { this.templatedItems.ForceUpdate(); }*/ IListProxy ITemplatedItemsView.ListProxy => TemplatedItems.ListProxy; ITemplatedItemsList ITemplatedItemsView.TemplatedItems => TemplatedItems; [EditorBrowsable(EditorBrowsableState.Never)] public TemplatedItemsList, TVisual> TemplatedItems { get; } TVisual IItemsView.CreateDefault(object item) => CreateDefault(item); void IItemsView.SetupContent(TVisual content, int index) => SetupContent(content, index); void IItemsView.UnhookContent(TVisual content) => UnhookContent(content); protected abstract TVisual CreateDefault(object item); protected virtual void SetupContent(TVisual content, int index) { } protected virtual void UnhookContent(TVisual content) { } static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue) { var element = newValue as Element; if (element == null) return; element.Parent = (Element)bindable; } protected virtual bool ValidateItemTemplate(DataTemplate template) => true; } }