I am upgrading an app from Xamarin to Maui. A form with a ListView that used to work perfectly, now will not accept input in Entry nor Editor controls, and Buttons do not work, UNLESS the item is the 1st or 2nd item in the list!!! (you can't make this stuff up, folks!).
The form has a button to add another element to the collection. That collection that is bound to the list view. Each element has some data entry fields (2 Entry controls, 1 Editor control) and also a Button.
If the list is empty, I can add 1 item, then add another. Everything works fine. If I add a 3rd (or more), the controls in those list items do not accept input. (!)
My XAML looks like this (I've simplified it a bit for clarity):
<ContentPage.Content><StackLayout Orientation="Vertical" VerticalOptions="StartAndExpand"><Button WidthRequest="200" HeightRequest="50" Text="Add New" HorizontalOptions="Center" Clicked="NewCommentClicked"/><BoxView HeightRequest="10" /><StackLayout Orientation="Vertical" VerticalOptions="StartAndExpand" HeightRequest="1200"><ListView x:Name="CommentsList" ItemsSource="{Binding .Comments}" SelectionMode="None" SeparatorVisibility="None" RowHeight="220" VerticalOptions="StartAndExpand"><ListView.ItemTemplate><DataTemplate><ViewCell><ViewCell.View><Grid><Grid.RowDefinitions><RowDefinition Height="40"/><RowDefinition Height="40"/><RowDefinition Height="40"/><RowDefinition Height="40"/><RowDefinition Height="5"/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="10"/><ColumnDefinition Width="90"/><ColumnDefinition Width="80"/><ColumnDefinition Width="400"/><ColumnDefinition Width="80"/></Grid.ColumnDefinitions><Label Grid.Row="0" Grid.Column="1" WidthRequest="80" Text="Rel (in):" VerticalOptions="Start" /><Entry Grid.Row="0" Grid.Column="2" WidthRequest="80" Text="{Binding RelDepth}" VerticalOptions="Start" /><Label Grid.Row="1" Grid.Column="1" WidthRequest="80" Text="Abs (ft):" /><Label Grid.Row="1" Grid.Column="2" WidthRequest="80" Text="{Binding AbsDepth}" /><Editor Grid.Row="0" Grid.Column="3" Grid.RowSpan="4" WidthRequest="400" HeightRequest="120" Text="{Binding Text}" Placeholder="Comment(s)..." BackgroundColor="#EFEFEF" Style="{StaticResource BigBlackTextEntry}" HorizontalOptions="StartAndExpand" VerticalOptions="Start"/><Button Grid.Row="3" Grid.Column="1" WidthRequest="90" HeightRequest="50" Text="Remove" /><BoxView Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="4" HeightRequest="1" BackgroundColor="Cyan" /></Grid></ViewCell.View></ViewCell></DataTemplate></ListView.ItemTemplate></ListView></StackLayout></StackLayout></ContentPage.Content>
In the code behind, I set the Binding context like this:
/// in the class instance data... private CommentBinding ViewModel { get; set; } /// elsewhere - in the constructor ViewModel = new CommentBinding() { Comments = theModels }; BindingContext = ViewModel; /// when an item is added private void NewCommentClicked(object sender, EventArgs e) { try { DepthModel newComment = new DepthModel() { RelDepth=0 }; newComment.RecalcAbsDepth(_startingAbsDepthInches); ViewModel.Comments.Add(newComment); ViewModel.NotifyChange(); } catch (Exception exception) { // log error... etc } }
The attached screen shot shows the 3 items in the list. The first two are editable and everyting works. The 3rd item does not allow any data entry (as if the controls were disabled - but we don't do that) and the button "Remove" does not respond.
Please note that the StackView that wraps the ListView had to be added to get the ListView to position properly (that is yet another mystery) - and the 1200 HeightRequest is an experiment to see if this is influencing the odd behavior - I'm not concerned about these right now.
All ideas welcome, of course.