2016-03-22 23:02:25 +03:00
|
|
|
|
using System.Collections;
|
2017-03-07 22:56:24 +03:00
|
|
|
|
using System.ComponentModel;
|
2016-06-17 13:10:18 +03:00
|
|
|
|
using Xamarin.Forms.Internals;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
namespace Xamarin.Forms
|
|
|
|
|
{
|
2016-06-17 13:10:18 +03:00
|
|
|
|
|
|
|
|
|
public abstract class ItemsView<TVisual> : View, ITemplatedItemsView<TVisual> where TVisual : BindableObject
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
public static readonly BindableProperty InfiniteScrollingProperty =
|
|
|
|
|
BindableProperty.Create<ItemsView, bool> (lv => lv.InfiniteScrolling, false);
|
|
|
|
|
|
|
|
|
|
public bool InfiniteScrolling
|
|
|
|
|
{
|
|
|
|
|
get { return (bool) GetValue (InfiniteScrollingProperty); }
|
|
|
|
|
set { SetValue (InfiniteScrollingProperty, value); }
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(IEnumerable), typeof(ItemsView<TVisual>), null, propertyChanged: OnItemsSourceChanged);
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create("ItemTemplate", typeof(DataTemplate), typeof(ItemsView<TVisual>), null, validateValue: ValidateItemTemplate);
|
|
|
|
|
|
|
|
|
|
internal ItemsView()
|
|
|
|
|
{
|
|
|
|
|
TemplatedItems = new TemplatedItemsList<ItemsView<TVisual>, TVisual>(this, ItemsSourceProperty, ItemTemplateProperty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable ItemsSource
|
|
|
|
|
{
|
|
|
|
|
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
|
|
|
|
|
set { SetValue(ItemsSourceProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataTemplate ItemTemplate
|
|
|
|
|
{
|
|
|
|
|
get { return (DataTemplate)GetValue(ItemTemplateProperty); }
|
|
|
|
|
set { SetValue(ItemTemplateProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*public void UpdateNonNotifyingList()
|
|
|
|
|
{
|
|
|
|
|
this.templatedItems.ForceUpdate();
|
|
|
|
|
}*/
|
|
|
|
|
|
2016-06-17 13:10:18 +03:00
|
|
|
|
IListProxy ITemplatedItemsView<TVisual>.ListProxy
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
get { return TemplatedItems.ListProxy; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 13:10:18 +03:00
|
|
|
|
ITemplatedItemsList<TVisual> ITemplatedItemsView<TVisual>.TemplatedItems { get { return TemplatedItems; } }
|
|
|
|
|
|
2017-03-07 22:56:24 +03:00
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
|
|
|
public TemplatedItemsList<ItemsView<TVisual>, TVisual> TemplatedItems { get; }
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
TVisual IItemsView<TVisual>.CreateDefault(object item)
|
|
|
|
|
{
|
|
|
|
|
return CreateDefault(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IItemsView<TVisual>.SetupContent(TVisual content, int index)
|
|
|
|
|
{
|
|
|
|
|
SetupContent(content, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IItemsView<TVisual>.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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-16 17:10:04 +03:00
|
|
|
|
static bool ValidateItemTemplate(BindableObject bindable, object value)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2017-09-16 17:10:04 +03:00
|
|
|
|
var listView = bindable as ListView;
|
|
|
|
|
if (listView == null)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
return true;
|
|
|
|
|
|
2017-09-16 17:10:04 +03:00
|
|
|
|
var isRetainStrategy = listView.CachingStrategy == ListViewCachingStrategy.RetainElement;
|
|
|
|
|
var isDataTemplateSelector = listView.ItemTemplate is DataTemplateSelector;
|
|
|
|
|
if (isRetainStrategy && isDataTemplateSelector)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|