I receive the following error when I use a Side Drawer inside a tab view.
When you initially navigate to the tab everything works fine. if you navigate away and come back to the tab the following error arises
Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Is this a known issue?
7 Answers, 1 is accepted
This error isn't specifically related to UI for Xamarin, but rather because you're attempting to add an element that already exists. This is usually happens when you have a named instance of a control and navigating back to a cached page instance (which is what Xamarin.Forms does on Android)..
Option 1 (recommended)
To eliminate this, try removing the x:Name of the SideDrawer so that new instances can be created without have a conflict of the other SideDrawer in memory. Especially if you're trying do this navigation in a single "global view model", "navigation helper class" or Tabbed page, because the application retains instances of the views.
Option 2 (not recommended, has performance and lifecycle implications)
If you need to keep the name, try using new instances of the pages instead of using cached backstack.
Further Investigation
If this doesn't help, please reply back with the code I can use to reproduce the exception so that I can investigate directly.
Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Removing the name does not solve the issue.
The issue is that the tab view I'm nesting the side drawer inside seems to be keeping a cache of the side drawer.
I don't leave the page so it's not a navigation issue, why is the tab view recreating the tab views again rather than just using the cached element.
I have no problem using other named instances inside the tab view it just seems to be the side drawer control
I've tested this scenario again and it works as expected, I've attached the demo (although the solution name is TabbedPage, it uses a TabView).
Here's a GIF of it at runtime:
Here is the code:
<
ContentPage
...>
<
telerikPrimitives:RadTabView
>
<
telerikPrimitives:RadTabView.Items
>
<
telerikPrimitives:TabViewItem
HeaderText
=
"Tab 1"
>
<
telerikPrimitives:TabViewItem.Content
>
<
telerikPrimitives:RadSideDrawer
x:Name
=
"drawer"
DrawerLocation
=
"Bottom"
IsOpen
=
"True"
DrawerLength
=
"200"
>
<
telerikPrimitives:RadSideDrawer.MainContent
>
<
Label
Text
=
"Main content"
/>
</
telerikPrimitives:RadSideDrawer.MainContent
>
<
telerikPrimitives:RadSideDrawer.DrawerContent
>
<
StackLayout
>
<
Button
Text
=
"Mail"
/>
<
Button
Text
=
"Calendar"
/>
<
Button
Text
=
"People"
/>
<
Button
Text
=
"Tasks"
/>
</
StackLayout
>
</
telerikPrimitives:RadSideDrawer.DrawerContent
>
</
telerikPrimitives:RadSideDrawer
>
</
telerikPrimitives:TabViewItem.Content
>
</
telerikPrimitives:TabViewItem
>
<
telerikPrimitives:TabViewItem
HeaderText
=
"Tab 2"
>
<
telerikPrimitives:TabViewItem.Content
>
<
Label
Text
=
"ContentPage in Tab 2"
HorizontalOptions
=
"Center"
VerticalOptions
=
"Center"
/>
</
telerikPrimitives:TabViewItem.Content
>
</
telerikPrimitives:TabViewItem
>
<
telerikPrimitives:TabViewItem
HeaderText
=
"Tab 3"
>
<
telerikPrimitives:TabViewItem.Content
>
<
Label
Text
=
"ContentPage in Tab 3"
HorizontalOptions
=
"Center"
VerticalOptions
=
"Center"
/>
</
telerikPrimitives:TabViewItem.Content
>
</
telerikPrimitives:TabViewItem
>
</
telerikPrimitives:RadTabView.Items
>
</
telerikPrimitives:RadTabView
>
</
ContentPage
>
Further Investigation
At this point, I can only conlcude this is unrelated to the SideDrawer itself, but rather something that's in the Main or Drawer content. In order to investigate further, we need to debug the problem directly. Can you update my attached demo so that it replicates the exception and send it back?
Since this is a forum thread, you can't attach a ZIP file. You can use a file sharing option like DropBox or OneDrive and share a download link (be sure to delete the bin/obj folders before zipping it, this significantly reduces the zip size).
I look forward to your reply.
Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Hi Lance,
Following your sample, I have been investigating what is exactly causing the exception.
I began to remove the elements one by one to find the culprit.
Here is what I found:
Adding a StackLayout to the MainContent causes the exception, If possible see if this replicates for you?
Adding any layout to the main content as the base layout causes the exception.
Only by adding a single control like a label to the main content property will allow me to avoid the exception.
Let me know if you can replicate what I am seeing
just found this I will update and test the release:
https://www.telerik.com/support/whats-new/xamarin-ui/release-history/ui-for-xamarin-r1-2018-(version-2018-1-315-240)
The new release has resolved the issue.
Thank you, Lance, for your help on this issue.
Really appreciate it,
Thanks again
John
I'm happy that you're up and running! My apologies for not ensuring you were using latest release sooner, let us know if you have any further questions or concerns.
Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik