Home > Software design >  During scrolling ListView error "Cannot access a disposed object"
During scrolling ListView error "Cannot access a disposed object"

Time:01-13

I got error:

'Cannot access a disposed object. Object name: 'Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer'.'.

It happen when I am adding more items to ListView and I trying to scrolling.

This is my definition for ListView in XAML:

<ListView x:Name="PlayerList" ItemsSource="{Binding Players}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10,0,10,0" HasUnevenRows="True" SelectionMode="None" >
    <ListView.ItemTemplate>
        <DataTemplate x:DataType="x:String">
            <ViewCell>
                <Frame BorderColor="{StaticResource PurpleElement1}" BackgroundColor="{StaticResource PurpleElement1}" Margin="5" CornerRadius="7" >
                   <Label Text="{Binding .}" HorizontalOptions="Center" VerticalOptions="Center" Margin="5,0,5,0" />
                </Frame>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Players is List<String>

Everything work correctly when definition look like this:

<ListView x:Name="PlayerList" ItemsSource="{Binding Players}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10,0,10,0" HasUnevenRows="True" SelectionMode="None" />

But I would like to define the appearance of my list.

CodePudding user response:

I found this issue on github https://github.com/dotnet/maui/issues/11323. Unfortunately, it doesn't seem like the bug will be fixed soon. I was able to get around it by placing the frame in Grid.

<ListView x:Name="PlayerList" ItemsSource="{Binding Players}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10,0,10,0" HasUnevenRows="True" SelectionMode="None" >
    <ListView.ItemTemplate>
        <DataTemplate x:DataType="x:String">
            <ViewCell>
                <Grid>
                    <Frame BorderColor="{StaticResource PurpleElement1}" BackgroundColor="{StaticResource PurpleElement1}" Margin="5" CornerRadius="7" >
                        <Label Text="{Binding .}" HorizontalOptions="CenterAndExpand" VerticalOptions="Center" Margin="5,0,5,0" HeightRequest="50"/>
                    </Frame>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
  • Related