Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions DragDropGridView/DragDropGridView.Drag.Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ public partial class DragDropGridView
private void UpdateDisableScrollView(bool isDisabled)
{
#if ANDROID
if (_scrollView != null)
{
InternalLogger.Debug(Tag, () => $"UpdateScrollView( disabled: {isDisabled} )");
((UntouchableScrollviewHandler)_scrollView.Handler!).UpdateDisableScrolling(isDisabled);
}
if (_scrollView?.Handler is UntouchableScrollviewHandler scrollHandler &&
scrollHandler.PlatformView != null)
{
InternalLogger.Debug(Tag, () => $"UpdateScrollView( disabled: {isDisabled} )");
scrollHandler.UpdateDisableScrolling(isDisabled);
}

if (_refreshView != null)
{
InternalLogger.Debug(Tag, () => $"UpdateRefreshView( disabled: {isDisabled} )");
((UntouchableRefreshViewHandler)_refreshView.Handler!).UpdateDisableScrolling(isDisabled);
}
if (_refreshView?.Handler is UntouchableRefreshViewHandler refreshHandler &&
refreshHandler.PlatformView != null)
{
InternalLogger.Debug(Tag, () => $"UpdateRefreshView( disabled: {isDisabled} )");
refreshHandler.UpdateDisableScrolling(isDisabled);
}
#elif !WINDOWS
if (_scrollView != null)
{
Expand Down
29 changes: 26 additions & 3 deletions DragDropGridView/DragDropGridView.ItemsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public partial class DragDropGridView
default(DataTemplate),
propertyChanged: OnItemTemplateChanged);

public static readonly BindableProperty ItemTemplateSelectorProperty = BindableProperty.Create(
nameof(ItemTemplateSelector),
typeof(DataTemplateSelector),
typeof(DragDropGridView),
default(DataTemplateSelector),
propertyChanged: OnItemTemplateChanged);

public IEnumerable ItemsSource
{
get => (IEnumerable)GetValue(ItemsSourceProperty);
Expand All @@ -31,6 +38,12 @@ public DataTemplate ItemTemplate
set => SetValue(ItemTemplateProperty, value);
}

public DataTemplateSelector ItemTemplateSelector
{
get => (DataTemplateSelector)GetValue(ItemTemplateSelectorProperty);
set => SetValue(ItemTemplateSelectorProperty, value);
}

private static void OnItemsSourceChanged(BindableObject bindable, object? oldValue, object? newValue)
{
if (bindable is not DragDropGridView gridLayout)
Expand All @@ -52,7 +65,7 @@ private static void OnItemsSourceChanged(BindableObject bindable, object? oldVal

foreach (var item in (IEnumerable)newValue)
{
if (gridLayout.ItemTemplate.CreateContent() is not View view)
if (gridLayout.GetTemplateForItem(item)?.CreateContent() is not View view)
{
continue;
}
Expand Down Expand Up @@ -89,7 +102,7 @@ private static void OnItemTemplateChanged(BindableObject bindable, object oldVal

foreach (var item in gridLayout.ItemsSource)
{
if (gridLayout.ItemTemplate.CreateContent() is not View view)
if (gridLayout.GetTemplateForItem(item)?.CreateContent() is not View view)
{
continue;
}
Expand All @@ -111,7 +124,7 @@ private void ItemsSourceCollectionChanged(object? sender, NotifyCollectionChange
case NotifyCollectionChangedAction.Add when e.NewItems is not null:
foreach (var item in e.NewItems)
{
if (ItemTemplate.CreateContent() is not View view)
if (GetTemplateForItem(item)?.CreateContent() is not View view)
{
continue;
}
Expand Down Expand Up @@ -155,5 +168,15 @@ private void ItemsSourceCollectionChanged(object? sender, NotifyCollectionChange
default:
throw new ArgumentOutOfRangeException();
}

}

private DataTemplate GetTemplateForItem(object item)
{
if (ItemTemplateSelector != null)
{
return ItemTemplateSelector.SelectTemplate(item, this);
}
return ItemTemplate;
}
}