diff --git a/DragDropGridView/DragDropGridView.Drag.Utilities.cs b/DragDropGridView/DragDropGridView.Drag.Utilities.cs index 0faefe5..35f1c75 100644 --- a/DragDropGridView/DragDropGridView.Drag.Utilities.cs +++ b/DragDropGridView/DragDropGridView.Drag.Utilities.cs @@ -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) { diff --git a/DragDropGridView/DragDropGridView.ItemsSource.cs b/DragDropGridView/DragDropGridView.ItemsSource.cs index c7a49d7..fcb6883 100644 --- a/DragDropGridView/DragDropGridView.ItemsSource.cs +++ b/DragDropGridView/DragDropGridView.ItemsSource.cs @@ -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); @@ -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) @@ -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; } @@ -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; } @@ -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; } @@ -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; } } \ No newline at end of file