Listview does not work as expected
See original GitHub issueI’ve build the following Component using a ListView to display some buttons with actions. If i open the menu and calling a Action for 23rd time, i will cause an Exception saying ‘system.exception: itemtemplate count has exceeded the limit of 23’. CollectionView instead will not cause any Exception. Is this a Maui bug or a Reactor-Maui bug? Even using the MauiControls.ListViewCachingStrategy.RecycleElementAndDataTemplate will not prevent this exception.
`public sealed class ActionMenuOverlay : Component { private IEnumerable<MenuAction> _menuActions = Enumerable.Range(0, 10).Select(x => new MenuAction {Text = “Im an action”});
public override VisualNode Render()
{
var parameter = GetParameter<ActionMenuOverlayParameters>();
return new ContentView
{
new Grid("2*,5*", "1*,1*")
{
//new CollectionView()
//.ItemsSource(_menuActions, RenderMenuAction2)
//.ItemsLayout(new VerticalLinearItemsLayout())
//.BackgroundColor(Colors.White)
//.GridColumn(1)
new ListView(MauiControls.ListViewCachingStrategy.RecycleElementAndDataTemplate)
.ItemsSource(_menuActions, RenderMenuAction)
.BackgroundColor(Colors.White)
.GridColumn(1)
}
.OnTapped(OnGridTapped)
.BackgroundColor(Colors.Transparent)
}
.AbsoluteLayoutFlags(AbsoluteLayoutFlags.SizeProportional)
.AbsoluteLayoutBounds(0,0,1,1)
.IsVisible(parameter.Value.IsVisible)
.ZIndex(25);
}
private ViewCell RenderMenuAction(MenuAction menuAction)
{
return new ViewCell
{
new Button()
.BackgroundColor(Colors.Transparent)
.Text(menuAction.Text)
.TextColor(Colors.Black)
.OnClicked(() =>
{
menuAction.Action.Invoke();
HideActionMenuOverlay();
})
};
}
private VisualNode RenderMenuAction2(MenuAction menuAction)
=> new Button()
.BackgroundColor(Colors.Transparent)
.Text(menuAction.Text)
.TextColor(Colors.Black)
.OnClicked(() =>
{
menuAction.Action.Invoke();
HideActionMenuOverlay();
});
private void OnGridTapped()
{
System.Diagnostics.Debug.WriteLine("Grid tapped");
HideActionMenuOverlay();
}
private void HideActionMenuOverlay()
{
var parameter = GetParameter<ActionMenuOverlayParameters>();
parameter.Set(x => x.IsVisible = false);
}
}`
Issue Analytics
- State:
- Created 3 months ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
android - ListView adapter does not behave as expected
I'm having a problem that is making me crazy. Every adapters that I've made before with the same code worked perfectly, however this...
Read more >ListView SelectionType.Multiple doesn't work as expected
Hi all, I'm trying to set up a ListViewwith multiple selections supported during runtime. Making items, binding and everything else ...
Read more >The ItemTapped event for a grouped ListView is not ...
The ItemTapped event for a grouped ListView is not working as expected. ItemTappedEventArgs.Group is populated as expected, however ...
Read more >Case list view not working as expected in community
I have created a list view on the case which is being used in a community. When a community user creates a record,...
Read more >Lightning List Vew Search Not Returning Expected Results
When you search a list view, only the first 2,000 records in the list view are searched. Share.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi, in Android there is a limit of 23 for the maximum number of DataTemplate that can be created and linked to a ListView (https://github.com/xamarin/Xamarin.Forms/issues/2931). Current implementation of the ListView in MauiReactor could easily reach that limit if you are going to pass to the list view a different items source at each render call (in you case you are re-rendering the component everytime a menu item is clicked).
So I can suggest a couple of things:
Starting from 1.0.133, MauiReactor tries to reuse the data template as much as possible. The limit under Android could be anyway hit under certain circumstances like when the list view is hot reloaded more than 23 times.