Hello,
Welcome to Microsoft Q&A!
Based on your words, you only have panels and controls in your code. IsEnabled property only exists in elements inherited from Control Object. Panels like StackPanel and Grid don't have such a property. So you need to find out if an element is a control or a panel. You could use Panel.Children Property to get all the children objects of the panel and try to find all the controls.
Here is the code that you could use:
private void MyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
//MyPanel is the target panel.
foreach (UIElement element in MyPanel.Children)
{
FindControl(element);
}
}
void FindControl(UIElement uiElement)
{
//if it is a panel
if (uiElement is Panel)
{
Panel panel = uiElement as Panel;
foreach (UIElement element in panel.Children)
{
//call the method itself again.
FindControl(element);
}
}
else if (uiElement is Control)
{
//if it is a control, set the isenable property.
Control control = uiElement as Control;
control.IsEnabled = false;
}
}
Thank you.