How to get the stacklayout that contains a button when the button is clicked?

241 views Asked by At

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

There are 1 answers

2
Cfun On BEST ANSWER

Use Parent property

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