@@ -5,127 +5,127 @@ namespace Maui.Controls.Sample.Issues;
55[ Issue ( IssueTracker . Github , 31535 , "[iOS] Crash occurred on CarouselView2 when deleting last one remaining item with loop as false" , PlatformAffected . iOS ) ]
66public class Issue31535 : ContentPage
77{
8- ObservableCollection < string > _items = new ( ) ;
9- public ObservableCollection < string > Items
10- {
11- get => _items ;
12- set
13- {
14- _items = value ;
15- OnPropertyChanged ( ) ;
16- }
17- }
18- public Issue31535 ( )
19- {
20- // Start with empty collection to test all scenarios
21- Items = new ObservableCollection < string > ( ) ;
8+ ObservableCollection < string > _items = new ( ) ;
9+ public ObservableCollection < string > Items
10+ {
11+ get => _items ;
12+ set
13+ {
14+ _items = value ;
15+ OnPropertyChanged ( ) ;
16+ }
17+ }
18+ public Issue31535 ( )
19+ {
20+ // Start with empty collection to test all scenarios
21+ Items = new ObservableCollection < string > ( ) ;
2222
23- // Create CarouselView
24- var carousel = new CarouselView2
25- {
26- Loop = false ,
27- HeightRequest = 200 ,
28- ItemsSource = Items ,
29- AutomationId = "TestCarouselView" ,
30- ItemTemplate = new DataTemplate ( ( ) =>
31- {
32- var border = new Border
33- {
34- Margin = 10 ,
35- WidthRequest = 200 ,
36- BackgroundColor = Colors . Red
37- } ;
23+ // Create CarouselView
24+ var carousel = new CarouselView2
25+ {
26+ Loop = false ,
27+ HeightRequest = 200 ,
28+ ItemsSource = Items ,
29+ AutomationId = "TestCarouselView" ,
30+ ItemTemplate = new DataTemplate ( ( ) =>
31+ {
32+ var border = new Border
33+ {
34+ Margin = 10 ,
35+ WidthRequest = 200 ,
36+ BackgroundColor = Colors . Red
37+ } ;
3838
39- var label = new Label ( ) ;
40- label . SetBinding ( Label . TextProperty , "." ) ;
39+ var label = new Label ( ) ;
40+ label . SetBinding ( Label . TextProperty , "." ) ;
4141
42- border . Content = label ;
43- return border ;
44- } )
45- } ;
42+ border . Content = label ;
43+ return border ;
44+ } )
45+ } ;
4646
47- // Create Buttons for testing different scenarios
48- var addSingleItemButton = new Button
49- {
50- AutomationId = "AddSingleItemButton" ,
51- Text = "Add Single Item"
52- } ;
47+ // Create Buttons for testing different scenarios
48+ var addSingleItemButton = new Button
49+ {
50+ AutomationId = "AddSingleItemButton" ,
51+ Text = "Add Single Item"
52+ } ;
5353
54- var removeSingleItemButton = new Button
55- {
56- AutomationId = "RemoveSingleItemButton" ,
57- Text = "Remove Single Item"
58- } ;
54+ var removeSingleItemButton = new Button
55+ {
56+ AutomationId = "RemoveSingleItemButton" ,
57+ Text = "Remove Single Item"
58+ } ;
5959
60- var addMultipleItemsButton = new Button
61- {
62- AutomationId = "AddMultipleItemsButton" ,
63- Text = "Add Multiple Items"
64- } ;
60+ var addMultipleItemsButton = new Button
61+ {
62+ AutomationId = "AddMultipleItemsButton" ,
63+ Text = "Add Multiple Items"
64+ } ;
6565
66- var removeAllItemsButton = new Button
67- {
68- AutomationId = "RemoveAllItemsButton" ,
69- Text = "Remove All Items"
70- } ;
66+ var removeAllItemsButton = new Button
67+ {
68+ AutomationId = "RemoveAllItemsButton" ,
69+ Text = "Remove All Items"
70+ } ;
7171
72- var itemCountLabel = new Label
73- {
74- Text = $ "Items Count: { Items . Count } ",
75- HorizontalOptions = LayoutOptions . Center
76- } ;
72+ var itemCountLabel = new Label
73+ {
74+ Text = $ "Items Count: { Items . Count } ",
75+ HorizontalOptions = LayoutOptions . Center
76+ } ;
7777
78- // Event handlers
79- addSingleItemButton . Clicked += ( s , e ) =>
80- {
81- Items . Add ( $ "Item { Items . Count + 1 } ") ;
82- itemCountLabel . Text = $ "Items Count: { Items . Count } ";
83- } ;
78+ // Event handlers
79+ addSingleItemButton . Clicked += ( s , e ) =>
80+ {
81+ Items . Add ( $ "Item { Items . Count + 1 } ") ;
82+ itemCountLabel . Text = $ "Items Count: { Items . Count } ";
83+ } ;
8484
85- removeSingleItemButton . Clicked += ( s , e ) =>
86- {
87- if ( Items . Count > 0 )
88- {
89- Items . RemoveAt ( Items . Count - 1 ) ;
90- itemCountLabel . Text = $ "Items Count: { Items . Count } ";
91- }
92- } ;
85+ removeSingleItemButton . Clicked += ( s , e ) =>
86+ {
87+ if ( Items . Count > 0 )
88+ {
89+ Items . RemoveAt ( Items . Count - 1 ) ;
90+ itemCountLabel . Text = $ "Items Count: { Items . Count } ";
91+ }
92+ } ;
9393
94- addMultipleItemsButton . Clicked += ( s , e ) =>
95- {
96- var currentCount = Items . Count ;
97- Items . Add ( $ "Item { currentCount + 1 } ") ;
98- Items . Add ( $ "Item { currentCount + 2 } ") ;
99- Items . Add ( $ "Item { currentCount + 3 } ") ;
100- itemCountLabel . Text = $ "Items Count: { Items . Count } ";
101- } ;
94+ addMultipleItemsButton . Clicked += ( s , e ) =>
95+ {
96+ var currentCount = Items . Count ;
97+ Items . Add ( $ "Item { currentCount + 1 } ") ;
98+ Items . Add ( $ "Item { currentCount + 2 } ") ;
99+ Items . Add ( $ "Item { currentCount + 3 } ") ;
100+ itemCountLabel . Text = $ "Items Count: { Items . Count } ";
101+ } ;
102102
103- removeAllItemsButton . Clicked += ( s , e ) =>
104- {
105- Items . Clear ( ) ;
106- itemCountLabel . Text = $ "Items Count: { Items . Count } ";
107- } ;
103+ removeAllItemsButton . Clicked += ( s , e ) =>
104+ {
105+ Items . Clear ( ) ;
106+ itemCountLabel . Text = $ "Items Count: { Items . Count } ";
107+ } ;
108108
109- Content = new VerticalStackLayout
110- {
111- Spacing = 10 ,
112- Padding = 20 ,
113- Children =
114- {
115- new Label
116- {
117- Text = "CarouselView2 Loop=false Test" ,
118- FontSize = 18 ,
119- HorizontalOptions = LayoutOptions . Center
120- } ,
121- itemCountLabel ,
122- carousel ,
123- addSingleItemButton ,
124- removeSingleItemButton ,
125- addMultipleItemsButton ,
126- removeAllItemsButton
127- }
128- } ;
129- BindingContext = this ;
130- }
109+ Content = new VerticalStackLayout
110+ {
111+ Spacing = 10 ,
112+ Padding = 20 ,
113+ Children =
114+ {
115+ new Label
116+ {
117+ Text = "CarouselView2 Loop=false Test" ,
118+ FontSize = 18 ,
119+ HorizontalOptions = LayoutOptions . Center
120+ } ,
121+ itemCountLabel ,
122+ carousel ,
123+ addSingleItemButton ,
124+ removeSingleItemButton ,
125+ addMultipleItemsButton ,
126+ removeAllItemsButton
127+ }
128+ } ;
129+ BindingContext = this ;
130+ }
131131}
0 commit comments