I have an error that only showed up today. until yesterday it worked fine. in the meantime i have updated visual studio.
xamarin forms is 5.0
the error reports:
Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView () on the child's parent first. '
I have a scrollview which contains a variety of information (like whatsapp).
the information is contained inpublic ObservableCollection <FlowNote> FlowNoteList {get {return Get <ObservableCollection <FlowNote>> (); } set {Set (value); OnPropertyChanged (); }}
when I delete an element it generates the error.
FlowNote fn = FlowNoteList.SingleOrDefault (Predicate => Predicate.IdNota == idnote); FlowNoteList.Remove (fn);
except in case it is the last element ...
xaml è:
<ScrollView VerticalOptions="Start" Margin="0,0,0,50"> <StackLayout x:Name="FlowStackLayout" VerticalOptions="Start"> <ListView x:Name="FlowListView" ItemsSource="{Binding FlowNoteList}" IsVisible="True" HasUnevenRows="True" SeparatorVisibility="Default"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <SwipeView x:Name="swipView" SwipeStarted="SwipeView_SwipeStarted" SwipeEnded="SwipeView_SwipeEnded"> <SwipeView.LeftItems> <SwipeItems> <SwipeItem Text="Share" BackgroundColor="#2196F3" Invoked="OnShareSwipeItemInvoked" > <SwipeItem.IconImageSource> <FontImageSource Color="Black" Size="15" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.Share}"></FontImageSource> </SwipeItem.IconImageSource> </SwipeItem> <SwipeItem Text="Edit" IsVisible="{Binding isMe, Converter={StaticResource isMeBoolInvertConverter}}" BackgroundColor="#2196F3" Invoked="OnEditNoteSwipeItemInvoked" > <SwipeItem.IconImageSource> <FontImageSource Color="Black" Size="15" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.CommentEdit}"></FontImageSource> </SwipeItem.IconImageSource> </SwipeItem> </SwipeItems> </SwipeView.LeftItems> <SwipeView.RightItems> <SwipeItems> <SwipeItem Text="Delete" IsVisible="{Binding isMe, Converter={StaticResource isMeBoolInvertConverter}}" BackgroundColor="#2196F3" Command="{Binding Path=BindingContext.UserDeleteNotaCommand, Source={x:Reference FlowStackLayout}}" CommandParameter="{Binding IdNota}" > <SwipeItem.IconImageSource> <FontImageSource Color="Red" Size="15" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.Delete}"></FontImageSource> </SwipeItem.IconImageSource> </SwipeItem> </SwipeItems> </SwipeView.RightItems> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="40"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="40"/> </Grid.ColumnDefinitions> <Frame Style="{Binding isMe, Converter={StaticResource IntToFrameChatBackgroundConverter}}" Grid.Column="{Binding isMe}" Margin="5" Grid.ColumnSpan="2" > <StackLayout Style="{Binding isMe, Converter={StaticResource IntToFrameChatBackgroundConverter}}" Grid.Column="{Binding isMe}" Margin="5" Grid.ColumnSpan="2" > <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition Width="20"/> </Grid.ColumnDefinitions> <Label Text="{Binding User.Username}" TextColor="Black" IsVisible="{Binding isMe, Converter={StaticResource isMeBoolConverter}}" Margin="2" FontSize="12" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"/> <Label Text="{Binding Data, StringFormat=' {0:dd-MMM-yy HH:mm}'}" Grid.Column="1" TextColor="Black" Margin="2" FontSize="12" HorizontalOptions="EndAndExpand" VerticalOptions="StartAndExpand"/> <Image Grid.Column="2" HorizontalOptions="Center"> <Image.GestureRecognizers> <TapGestureRecognizer Tapped="RowMenu_tapped" CommandParameter="{Binding PathDoc}" NumberOfTapsRequired="1"></TapGestureRecognizer> </Image.GestureRecognizers> <Image.Source> <FontImageSource Color="Black" Size="25" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.DotsVertical}"></FontImageSource> </Image.Source> </Image> </Grid> <Label Text="{Binding Titolo}" TextColor="Black" IsVisible="{Binding Titolo, Converter={StaticResource StringNullOrEmptyBoolConverter}}" Margin="2" FontAttributes="Bold" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"> <Label.GestureRecognizers> <TapGestureRecognizer Tapped="OnTitoloTapped" NumberOfTapsRequired="2"/> </Label.GestureRecognizers> </Label> <Label Text="{Binding Nota}" LineBreakMode="WordWrap" TextColor="Black" IsVisible="{Binding Nota, Converter={StaticResource StringNullOrEmptyBoolConverter}}" Margin="2" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"> <Label.GestureRecognizers> <TapGestureRecognizer Tapped="OnEditNoteTapped" NumberOfTapsRequired="2"/> </Label.GestureRecognizers> </Label> <Image IsVisible="{Binding AllegatoList, Converter={StaticResource ObservableCollectionMultipleBoolConverter}}" HorizontalOptions="Start"> <Image.Source> <FontImageSource Color="Black" Size="25" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.Attachment}"></FontImageSource> </Image.Source> </Image> <StackLayout x:Name="BindableLayoutAllegati" BindableLayout.ItemsSource="{Binding AllegatoList}"> <!--https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/bindable-layouts--> <BindableLayout.ItemTemplate> <DataTemplate> <StackLayout HorizontalOptions="CenterAndExpand"> <Grid IsVisible="{Binding PathDoc, Converter={StaticResource IsAudioValueConverter}}" HeightRequest="60"> <Grid.ColumnDefinitions> <ColumnDefinition Width="60"/> <ColumnDefinition Width="150"/> <ColumnDefinition Width="60"/> </Grid.ColumnDefinitions> <Image Source="{Binding Path=BindingContext.IconAudioPlayer, Source={x:Reference ImageAllegato}}" HeightRequest="50" WidthRequest="50" VerticalOptions="Center" HorizontalOptions="Center"> <Image.GestureRecognizers> <TapGestureRecognizer Command="{Binding Path=BindingContext.PlayAudioCommand, Source={x:Reference ImageAllegato}}" CommandParameter="{Binding PathDoc}" NumberOfTapsRequired="1"></TapGestureRecognizer> </Image.GestureRecognizers> </Image> <StackLayout Grid.Column="1"> <Label Text="{Binding TicksAudioPlayer}" TextColor="White" FontAttributes="Bold" HorizontalOptions="Center" /> <Slider x:Name="SliderSongPlayDisplay" Value="{Binding PositionAudioPlayer}" HorizontalOptions="FillAndExpand" Minimum="0" Maximum="{Binding DurationAudioPlayer}" MinimumTrackColor="{StaticResource Primary}" ThumbColor="{StaticResource Primary}" /> </StackLayout> <Image Grid.Column="2" Source="{Binding PathDoc, Converter={StaticResource URLtoThumbValueConverter}}" HorizontalOptions="Center"/> </Grid> <!--<Label Text="{Binding Thumb}"/>--> <!--<Image x:Name="ImageAllegato" Source="{Binding PathDoc, Converter={StaticResource URLtoThumbValueConverter}, ConverterParameter={Binding IsLinkWeb}}" HorizontalOptions="Center">--> <!--<Label Text="{Binding NomeDoc}" TextColor="Black" IsVisible="{Binding NomeDoc, Converter={StaticResource StringNullOrEmptyBoolConverter}}" Margin="2" FontAttributes="Bold" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"/>--> <Image x:Name="ImageAllegato" HorizontalOptions="Center"> <Image.Source> <MultiBinding Converter="{StaticResource URLtoThumbMultiValueConverter}"> <Binding Path="PathDoc" /> <Binding Path="IsLinkWeb" /> <Binding Path="Thumb" /> </MultiBinding> </Image.Source> <Image.Triggers> <DataTrigger TargetType="Image" Binding="{Binding PathDoc, Converter={StaticResource IsAudioValueConverter}}" Value="True"> <Setter Property="IsVisible" Value="False" /> </DataTrigger> </Image.Triggers> <Image.GestureRecognizers> <TapGestureRecognizer Command="{Binding Path=BindingContext.ZoomPhotoCommand, Source={x:Reference ImageAllegato}}" CommandParameter="{Binding PathDoc}" NumberOfTapsRequired="2"></TapGestureRecognizer> </Image.GestureRecognizers> </Image> <Label Text="{Binding NoteDoc}" TextColor="Black" IsVisible="{Binding NoteDoc, Converter={StaticResource StringNullOrEmptyBoolConverter}}" Margin="2" FontAttributes="Bold" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"/> </StackLayout> </DataTemplate> </BindableLayout.ItemTemplate> </StackLayout> </StackLayout> </Frame> </Grid> </SwipeView> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </StackLayout> </ScrollView>
(test on Android)
Thanks...