XAML
C#
xaml.cs
C#
foreach (RadioButton rb in GroupBox:Name FirstGroupBox)) {
}does not work. How do I retrieve every RadioButton in the GroupBox?
XAML
xaml.cs
foreach (RadioButton rb in GroupBox:Name FirstGroupBox)) {
}does not work. How do I retrieve every RadioButton in the GroupBox?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sangeetha SRank #212 · 11.4K reputationPosted Dec 2, 2024, 12:03 AM EST
To retrieve all
RadioButtoncontrols within aGroupBoxin your XAML, you can use a simple method to iterate through the children of theGroupBox. Here's how you can do it in yourxaml.csfile:using System.Windows.Controls; // Assuming this is part of a method in your code-behind foreach (var child in FirstGroupBox.Children) { if (child is RadioButton rb) { Console.WriteLine(rb.Content); } }In this code:
FirstGroupBox.RadioButtonusing theiskeyword.