1
1
using System . Collections . ObjectModel ;
2
+ using System . Collections . Specialized ;
2
3
using System . Threading . Tasks ;
3
4
using Microsoft . Maui . Controls ;
4
5
using Microsoft . Maui . Controls . Handlers . Items ;
@@ -112,6 +113,45 @@ await CreateHandlerAndAddToWindow<LayoutHandler>(layout, async (handler) =>
112
113
Assert . NotNull ( handler . PlatformView ) ;
113
114
} ) ;
114
115
}
116
+
117
+ #if ! ANDROID //https://github.com/dotnet/maui/pull/24610
118
+ [ Fact ]
119
+ public async void DisconnectedCarouselViewDoesNotHookCollectionViewChanged ( )
120
+ {
121
+ SetupBuilder ( ) ;
122
+
123
+ CollectionChangedObservableCollection < int > data = new CollectionChangedObservableCollection < int > ( )
124
+ {
125
+ 1 ,
126
+ 2 ,
127
+ } ;
128
+
129
+ var template = new DataTemplate ( ( ) =>
130
+ {
131
+ return new Grid ( )
132
+ {
133
+ new Label ( )
134
+ } ;
135
+ } ) ;
136
+
137
+ var carouselView = new CarouselView ( )
138
+ {
139
+ ItemTemplate = template ,
140
+ ItemsSource = data
141
+ } ;
142
+
143
+ await CreateHandlerAndAddToWindow < CarouselViewHandler > ( carouselView , async ( handler ) =>
144
+ {
145
+ await Task . Delay ( 100 ) ;
146
+ Assert . NotNull ( handler . PlatformView ) ;
147
+ Assert . False ( data . IsCollectionChangedEventEmpty ) ;
148
+ } ) ;
149
+
150
+ carouselView . Handler ? . DisconnectHandler ( ) ;
151
+
152
+ Assert . True ( data . IsCollectionChangedEventEmpty ) ;
153
+ }
154
+ #endif
115
155
}
116
156
117
157
internal class CustomDataTemplateSelectorSelector : DataTemplateSelector
@@ -129,4 +169,17 @@ protected override DataTemplate OnSelectTemplate(object item, BindableObject con
129
169
return Template2 ;
130
170
}
131
171
}
132
- }
172
+
173
+ internal class CollectionChangedObservableCollection < T > : ObservableCollection < T > , INotifyCollectionChanged
174
+ {
175
+ NotifyCollectionChangedEventHandler collectionChanged ;
176
+
177
+ event NotifyCollectionChangedEventHandler INotifyCollectionChanged . CollectionChanged
178
+ {
179
+ add { collectionChanged += value ; base . CollectionChanged += value ; }
180
+ remove { collectionChanged -= value ; base . CollectionChanged -= value ; }
181
+ }
182
+
183
+ public bool IsCollectionChangedEventEmpty => collectionChanged is null ;
184
+ }
185
+ }
0 commit comments