xamarin stacklayout child removes itself

Clash Royale CLAN TAG#URR8PPP
xamarin stacklayout child removes itself
I have a simple Stacklayout that shows Buttons.
I want to be able to let children remove itself from the stacklayout.
Stacklayout
stacklayout
this project is just for testing purposes, so every button is linked to the same event-handler.
private void Button_Pressed_1(object sender, EventArgs e)
stack.Children.RemoveAt(stack.Children.Count - 1);
everything's fine until one button removes itself, then the following unsupported error appears:
Unhandled Exception:
System.NotSupportedException: Unable to activate instance of type
Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer from native
handle 0xbfb79bfc (key_handle 0x3e59524).
Has anyone an idea how to accomplish this? Since it's a nonSupportedException a simple try & catch didn't do the job
nonSupportedException
EDIT:
I got it working, i registered the eventhandler to the Pressed-Event. Appearently that was the problem, when using the Clicke-Event everything works just fine.
1 Answer
1
What 's version of Xamarin which you are using? I tried with Xamarin.Form 3.0.0.561731 and it worked well.
Please check my code as bellow:
Xaml page:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RemoveItSelf"
x:Class="RemoveItSelf.MainPage">
<StackLayout x:Name="stack">
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Button Text="Remove" Clicked="PressMeButton_Clicked"></Button>
</StackLayout>
</ContentPage>
Xaml.cs page:
namespace RemoveItSelf
public partial class MainPage : ContentPage
public MainPage()
InitializeComponent();
private void PressMeButton_Clicked(object sender, EventArgs e)
//stack.Children.RemoveAt(0);
stack.Children.RemoveAt(stack.Children.Count - 1);
I just tried your code and it worked. I don't get it why in my project the exception keeps getting raised
– Phil Noderer
Aug 10 at 10:24
Please share your xaml page also
– Nhan Phan
Aug 10 at 10:25
thanks, i got it working. See my edit in the post
– Phil Noderer
Aug 10 at 10:27
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I have also installed version 3.0.0.561731
– Phil Noderer
Aug 10 at 10:19