C# Xamarin上的异常:System.ObjectDisposedException:无法访问已处置对象';Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer';

C# Xamarin上的异常:System.ObjectDisposedException:无法访问已处置对象';Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer';,c#,android,xamarin,xamarin.forms,C#,Android,Xamarin,Xamarin.forms,我正在使用Xamarin.Forms为Android构建一个应用程序,目前我遇到以下错误:System.ObjectDisposedException:无法访问已处理对象“Xamarin.Forms.Platform.Android.fastrenders.LabelRenderer”。我使用的Xamarin.Forms版本是4.8.0.1364 我的XAML代码如下: <?xml version="1.0" encoding="UTF-8"?>

我正在使用
Xamarin.Forms
Android
构建一个应用程序,目前我遇到以下错误:
System.ObjectDisposedException:无法访问已处理对象“Xamarin.Forms.Platform.Android.fastrenders.LabelRenderer”。
我使用的
Xamarin.Forms
版本是
4.8.0.1364

我的
XAML
代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView
  x:Class="Peripass.YardAssetManagementApp.UI.Views.MainTaskListViewContent"
  xmlns="http://xamarin.com/schemas/2014/forms"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  xmlns:converters="clr-namespace:Peripass.Mobile.Framework.Converters;assembly=Peripass.Mobile.Framework"
  xmlns:d="http://xamarin.com/schemas/2014/forms/design"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:uiControls="clr-namespace:Peripass.Mobile.Framework.UIControls;assembly=Peripass.Mobile.Framework"
  mc:Ignorable="d"
  x:Name="tasksPage">
  <ContentView.Resources>
    <ResourceDictionary>
      <converters:ItemTappedEventArgsToTappedItemConverter x:Key="ItemTappedConverter" />
    </ResourceDictionary>
  </ContentView.Resources>
  <ContentView.Content>
    <!-- All Tasks -->
    <StackLayout
      BackgroundColor="White"
      VerticalOptions="FillAndExpand">
      <!-- ActivityIndicator -->
      <StackLayout
        Padding="0,20,0,0"
        BackgroundColor="White"
        IsVisible="{Binding Model.ShowLoadingIndicator}">
        <ActivityIndicator BackgroundColor="White" 
                               
                           Color="#28aa90" 
                           HeightRequest="40"
                           WidthRequest="40"
                           IsRunning="{Binding Model.ShowLoadingIndicator}"
                           IsVisible="{Binding Model.ShowLoadingIndicator}">

        </ActivityIndicator>
        <Label FontSize="14" Text="fetching tasks" TextColor="DimGray" HorizontalTextAlignment="Center" HorizontalOptions="FillAndExpand"></Label>
      </StackLayout>

      <RefreshView Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing, Mode=OneWay}">
        <CollectionView x:Name="tasks" ItemsSource="{Binding Model.AllTasks}" ItemSizingStrategy="MeasureAllItems" VerticalOptions="FillAndExpand">
          <CollectionView.ItemTemplate>
            <DataTemplate>
              <StackLayout BackgroundColor="{Binding RowBackGroundColor}">
                <StackLayout.GestureRecognizers>
                  <TapGestureRecognizer CommandParameter="{Binding TaskId}" Command="{Binding Source={x:Reference tasks}, Path=BindingContext.TappedGotoTaskDetailCommand}"/>
                </StackLayout.GestureRecognizers>
                <Grid>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="73" />
                    <RowDefinition Height="*" />
                  </Grid.RowDefinitions>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="65" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="75" />
                  </Grid.ColumnDefinitions>
                  <uiControls:PpIcon
                            Grid.Row="0"
                            Grid.Column="0"
                            Margin="5"
                            IconChar="{Binding LeftIconChar}"
                            IconColor="{Binding LeftIconColor}"
                            IconSize="42" />

                  <Grid Grid.Row="0" Grid.Column="1">
                    <Grid.RowDefinitions>
                      <RowDefinition Height="50*" />
                      <RowDefinition Height="50*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="*" />
                      <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Label
                      FontAttributes="Bold"
                      FontSize="21"
                      HorizontalTextAlignment="Start"
                      LineBreakMode="TailTruncation"
                      Text="{Binding TaskLine1}"
                      TextColor="{StaticResource PeripassBlack}"
                      TranslationY="7"
                      VerticalTextAlignment="Center" />
                    

                    <StackLayout
                              Grid.Row="0"
                              Grid.RowSpan="2"
                              Grid.Column="1"
                              Margin="0"
                              Padding="0"
                              Orientation="Horizontal"
                              Spacing="0"
                              TranslationX="4">
                      <Label
                                FontAttributes="Bold"
                                FontSize="21"
                                HorizontalOptions="End"
                                HorizontalTextAlignment="Start"
                                Text="{Binding StepProgressLineStepsDone}"
                                TextColor="{Binding RightIconColor}"
                                VerticalTextAlignment="Center" />

                      <Label
                                FontSize="21"
                                HorizontalOptions="End"
                                HorizontalTextAlignment="Start"
                                Text="/"
                                TextColor="{Binding RightIconColor}"
                                VerticalTextAlignment="Center" />

                      <Label
                                FontSize="21"
                                HorizontalOptions="End"
                                HorizontalTextAlignment="Start"
                                Text="{Binding StepProgressLineStepsTotal}"
                                TextColor="{Binding RightIconColor}"
                                VerticalTextAlignment="Center" />
                    </StackLayout>

                    <Label
                              Grid.Row="1"
                              Grid.Column="0"
                              FontSize="16"
                              HorizontalTextAlignment="Start"
                              LineBreakMode="TailTruncation"
                              Text="{Binding TaskLine2}"
                              TextColor="{StaticResource PeripassBlack}"
                              VerticalOptions="StartAndExpand"
                              VerticalTextAlignment="Center" />


                  </Grid>

                  <uiControls:PpIcon
                            Grid.Row="0"
                            Grid.Column="2"
                            Margin="15"
                            IconChar="{Binding RightIconChar}"
                            IconColor="{Binding RightIconColor}"
                            IconSize="42" />

                  <Label
                    Grid.Row="1"
                    Grid.Column="1"
                    Grid.ColumnSpan="2"
                    FontSize="16"
                    HorizontalTextAlignment="Start"
                    LineBreakMode="TailTruncation"
                    Text="{Binding DisplayName}"
                    TextColor="{StaticResource PeripassBlack}"
                    VerticalOptions="StartAndExpand"
                    VerticalTextAlignment="Center"
                    IsVisible="{Binding Source={x:Reference tasksPage}, Path=BindingContext.Model.IsSearching}"
                    />
                </Grid>
              </StackLayout>
            </DataTemplate>
          </CollectionView.ItemTemplate>
          <CollectionView.EmptyView>
            <StackLayout>
              <StackLayout HeightRequest="100" BackgroundColor="#D6D6D6" Margin="10,10,10,10">
                <Label HorizontalOptions="Center" VerticalOptions="CenterAndExpand" FontSize="20" Text="No tasks available" TextColor="{StaticResource PeripassBlack}"/>
              </StackLayout>
            </StackLayout>
          </CollectionView.EmptyView>
        </CollectionView>
      </RefreshView>
    </StackLayout>
  </ContentView.Content>
</ContentView>
我相信
XAML
中的这段代码就是罪魁祸首。更具体地说,
是标签的可见属性。如果我去掉这个,例外似乎不会发生

<Label
                    Grid.Row="1"
                    Grid.Column="1"
                    Grid.ColumnSpan="2"
                    FontSize="16"
                    HorizontalTextAlignment="Start"
                    LineBreakMode="TailTruncation"
                    Text="{Binding DisplayName}"
                    TextColor="{StaticResource PeripassBlack}"
                    VerticalOptions="StartAndExpand"
                    VerticalTextAlignment="Center"
                    IsVisible="{Binding Source={x:Reference tasksPage}, Path=BindingContext.Model.IsSearching}"
                    />


我已经搜索了一段时间,尝试了不同的方法,但似乎没有任何效果。如果您需要更多信息,请询问。

此问题已在最新版本的
Xamarin.forms 4.8.0.1687
中修复

遇到此问题的任何人请更新您的Xamarin.forms版本

下面是Github中的一些相关线程


更新到4.8.0.1687,然后重试。乍一看,这似乎已经解决了问题!:)太明显了。非常感谢。我会写一个答案,让你的答案更清楚,你能接受吗☑️ 在这个答案的左上角),这样我们就可以帮助更多有同样问题的人:)。
<Label
                    Grid.Row="1"
                    Grid.Column="1"
                    Grid.ColumnSpan="2"
                    FontSize="16"
                    HorizontalTextAlignment="Start"
                    LineBreakMode="TailTruncation"
                    Text="{Binding DisplayName}"
                    TextColor="{StaticResource PeripassBlack}"
                    VerticalOptions="StartAndExpand"
                    VerticalTextAlignment="Center"
                    IsVisible="{Binding Source={x:Reference tasksPage}, Path=BindingContext.Model.IsSearching}"
                    />