Reputation: 1110
In a Xamarin forms project I am trying to get a StackLayout from a button clicked event. The StackLayout can have 1-3 buttons when one is clicked it calls
static void PollButtonClick(object sender, EventArgs e)
{
Button button = sender as Button;
button.IsEnabled = false;
}
But I need to be able to disable all of the buttons. I tried looking for something like button.GetLayout so I could loop through the Children to find all the buttons but haven't found any methods for that.
Upvotes: 1
Views: 102
Reputation: 74144
You can use the Parent
property of the Element
, and then loop through the Children
of that Element
skipping the Button
that is the sender if need be.
Example:
void Handle_Clicked(object sender, System.EventArgs e)
{
foreach (var child in ((sender as Button).Parent as StackLayout).Children)
{
if (child is Button && !child.Equals(sender))
{
child.IsEnabled = false;
}
}
}
Upvotes: 4