c-sharpcorner.com/forums/how-do-i-uncheck-all-radio-buttons-at-one-time
XAML
C#
XAML.CS
C#
using System.Windows.Controls;
foreach (var child in FirstGroupBox.Children)
{
if (child is RadioButton rb)
{
rb.IsChecked = false;// Uncheck each RadioButton
}
}results in error message "GroupBox does not contain a definition for 'Children' ...." => snipboard.io/9dnwLZ.jpg

Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Dec 2, 2024, 1:20 PM EST
Hi Clyde,
The error occurs because
GroupBoxdoes not have aChildrenproperty directly. Instead, theGroupBoxtypically contains a single child element, which is often aPanel(likeStackPanel,Grid, etc.). To access the radio buttons, you need to first access the child panel within theGroupBox, then iterate over the elements in that panel. Here is the updated code but you can use the the element accordingly:XAML.CS
using System.Windows.Controls; // Access the child panel inside the GroupBox var panel = FirstGroupBox.Content as Panel; if (panel != null) { foreach (var child in panel.Children) { if (child is RadioButton rb) { rb.IsChecked = false; // Uncheck each RadioButton } } }Thank you!