0
votes

Im using a stacklayout that contains some other elements and a button.

<StackLayout x:Name="layout">
   <Button Text="Button" Clicked="Action"/>
<StackLayout/>

Is there a way to get the StackLayout that contains the button when it is clicked?

1
What are you trying to accomplish?Jason
I have an array that contains some other stacks and I want to get the stacklayout to delete it when the button is clickedSebastián Cueva

1 Answers

1
votes

Use Parent property

void Action(object sender, EventArgs args)
{
     var button = sender as Button;
     var stackLayout = button.Parent as StackLayout;
     stackLayout.Children.Remove(button); 
}