@@ -42,7 +42,9 @@ public class CardsView : Grid
4242
4343 public static readonly BindableProperty ItemTemplateProperty = BindableProperty . Create ( nameof ( ItemTemplate ) , typeof ( DataTemplate ) , typeof ( CardsView ) , propertyChanged : ( bindable , oldValue , newValue ) =>
4444 {
45- bindable . AsCardsView ( ) . ForceRedrawViews ( ) ;
45+ var cardView = bindable . AsCardsView ( ) ;
46+ cardView . OnItemTemplateChanged ( ) ;
47+ cardView . ForceRedrawViews ( ) ;
4648 } ) ;
4749
4850 public static readonly BindableProperty BackViewsDepthProperty = BindableProperty . Create ( nameof ( BackViewsDepth ) , typeof ( int ) , typeof ( CardsView ) , defaultValueCreator : b => b . AsCardsView ( ) . DefaultBackViewsDepth , propertyChanged : ( bindable , oldValue , newValue ) =>
@@ -806,17 +808,6 @@ await Task.WhenAll(
806808
807809 protected virtual async void OnSizeChanged ( )
808810 {
809- if ( CurrentView != null && ItemTemplate != null )
810- {
811- var currentViewPair = _viewsPool . FirstOrDefault ( p => p . Value . Contains ( CurrentView ) ) ;
812- if ( ! currentViewPair . Equals ( default ( KeyValuePair < object , List < View > > ) ) )
813- {
814- currentViewPair . Value . Clear ( ) ;
815- currentViewPair . Value . Add ( CurrentView ) ;
816- _viewsPool . Clear ( ) ;
817- _viewsPool . Add ( currentViewPair . Key , currentViewPair . Value ) ;
818- }
819- }
820811 await Task . Delay ( 1 ) ; // Workaround for https://github.com/AndreiMisiukevich/CardView/issues/194
821812 ForceRedrawViews ( ) ;
822813 RemoveUnprocessingChildren ( ) ;
@@ -1766,6 +1757,21 @@ private void SetItemsSource(IEnumerable oldCollection)
17661757 OnObservableCollectionChanged ( oldCollection , new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Reset ) ) ;
17671758 }
17681759
1760+ private void OnItemTemplateChanged ( )
1761+ {
1762+ if ( CurrentView != null )
1763+ {
1764+ var currentViewPair = _viewsPool . FirstOrDefault ( p => p . Value . Contains ( CurrentView ) ) ;
1765+ if ( ! currentViewPair . Equals ( default ( KeyValuePair < object , List < View > > ) ) )
1766+ {
1767+ currentViewPair . Value . Clear ( ) ;
1768+ currentViewPair . Value . Add ( CurrentView ) ;
1769+ _viewsPool . Clear ( ) ;
1770+ _viewsPool . Add ( currentViewPair . Key , currentViewPair . Value ) ;
1771+ }
1772+ }
1773+ }
1774+
17691775 private void SetNewIndex ( )
17701776 {
17711777 if ( ItemsCount <= 0 )
0 commit comments