滚动 ListView 时出现错误“无法访问已处置的对象”

问题描述 投票:0回答:2

我遇到错误:

'无法访问已处置的对象。对象名称: 'Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer'。'.

当我向 ListView 添加更多项目并尝试滚动时会发生这种情况。

这是我在 XAML 中对 ListView 的定义:

<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>

玩家是

List<String>

当定义如下时,一切正常:

<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" />

但我想定义我的列表的外观。

.net xamarin maui
2个回答
2
投票

我在github上发现了这个问题https://github.com/dotnet/maui/issues/11323。不幸的是,该错误似乎不会很快得到修复。我可以通过将框架放置在网格中来解决这个问题。

<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>

0
投票

你可以使用边框代替框架,就像这样

    <ScrollView Grid.Row="1"  Orientation="Vertical" VerticalScrollBarVisibility="Always">
    <StackLayout>
        <ListView x:Name="listViewCheques" ItemsSource="{Binding ChequesList}" SelectionMode="None" Margin="5" RowHeight="100" HasUnevenRows="True"   >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell >
                        <ViewCell.ContextActions >
                            <!--روش command-->
                            <!--<MenuItem Text="Delete" IsDestructive="True" Command="{Binding Path=BindingContext.DeleteCommand , Source={Reference MylistView}}" CommandParameter="{Binding .}"/>-->
                            <!--Click-->
                            <!--روش command-->
                            <MenuItem Text="حذف" IsDestructive="True" Command="{Binding Path=BindingContext.DeleteChequesCommand, Source={Reference listViewCheques}}" CommandParameter="{Binding ID}"/>
                            <MenuItem  Text="ارسال به سرور" IsDestructive="True" Command="{Binding Path=BindingContext.PostToRahkaran , Source={Reference listViewCheques}}" CommandParameter="{Binding ID}" />
                            <!--Click-->
                            <!--<MenuItem x:Name="BtnDelete" Text="حذف" IsDestructive="True" Clicked="BtnDelete_Clicked" />-->


                        </ViewCell.ContextActions>


                        <Border x:Name="framd2" BackgroundColor="WhiteSmoke"  >
                        <Border.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientStop Color="#6cc3f5" Offset="0.2"/>
                                    <GradientStop Color="White" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.Background>
                        <Border.StrokeShape>
                            <RoundRectangle CornerRadius="10"/>
                        </Border.StrokeShape>

                            <Grid Padding="0"  RowDefinitions="*,*,*" ColumnDefinitions="*,*,*,*,*,*" CascadeInputTransparent="True"  >
                                <Label Text="شناسه :" Grid.Row="0" Grid.Column="5" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara"/>
                                <Label Text="{Binding ID}" Grid.Column="4" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara"/>

                                <Label Text="تعداد چک:" Grid.Row="0" Grid.Column="3" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara"/>
                                <Label Text="{Binding ChequeCount}" Grid.Column="2" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara" FontSize="12"/>

                                <Label Text="تاریخ :" Grid.Row="0" Grid.Column="1" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara"/>
                                <Label Text="{Binding PersionDate}" Grid.Column="0" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara" FontSize="12"/>

                                <Label Text="ارسال:" Grid.Row="1" Grid.Column="5" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara"/>
                                <CheckBox IsChecked="{Binding IsSend}" Grid.Row="1"  Grid.Column="4"  VerticalOptions="Center" HorizontalOptions="End" IsEnabled="False"/>

                                <Label Text="استعلام:" Grid.Row="1" Grid.Column="3" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara"/>
                                <CheckBox IsChecked="{Binding IsAllinquery}" Grid.Row="1"  Grid.Column="2"  VerticalOptions="Center" HorizontalOptions="End" IsEnabled="False"/>

                                <Label Text="تایید:" Grid.Row="1" Grid.Column="1" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara"/>
                                <CheckBox IsChecked="{Binding IsAllAccept}" Grid.Row="1"  Grid.Column="0"  VerticalOptions="Center" HorizontalOptions="End" IsEnabled="False"/>

                                <Label Text="شرح :" Grid.Row="2" Grid.Column="5" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara"/>
                                <Label Text="{Binding Description}" Grid.Row="2"  Grid.Column="2" Grid.ColumnSpan="6" VerticalOptions="Center" HorizontalOptions="End" FontFamily="SGKara" FontSize="12"/>
                            </Grid>
                        </Border>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ScrollView>
© www.soinside.com 2019 - 2024. All rights reserved.