C# WPF中控件的模拟

C# WPF中控件的模拟,c#,wpf,winforms,C#,Wpf,Winforms,我有几个分组框,每个框中有3个单选按钮(它们都在网格中)。在WinForms中,我可以使用控件按名称和索引访问控件,如: groupbox1.Controls[0] 或 所以我需要在WPF中做的是:我有一个groupbox,我需要使用索引访问其中的某个单选按钮,就像在WinForms中一样。在WPF中可能吗?或者,我怎样才能找到groupbox的孩子们呢?这个问题与任何一个评论问题都不完全相同 假设您有以下设置 <GroupBox> <StackPanel x:Na

我有几个分组框,每个框中有3个单选按钮(它们都在网格中)。在WinForms中,我可以使用控件按名称和索引访问控件,如:

groupbox1.Controls[0] 

所以我需要在WPF中做的是:我有一个groupbox,我需要使用索引访问其中的某个单选按钮,就像在WinForms中一样。在WPF中可能吗?或者,我怎样才能找到groupbox的孩子们呢?

这个问题与任何一个评论问题都不完全相同

假设您有以下设置

<GroupBox>
    <StackPanel x:Name="MyRadioButtons">
        <RadioButton x:Name="radio1">Radio1</RadioButton>
        <RadioButton x:Name="radio2">Radio2</RadioButton>
        <RadioButton x:Name="radio3">Radio3</RadioButton>
    </StackPanel>
</GroupBox>
可能与以下类似的声音重复:
<GroupBox>
    <StackPanel x:Name="MyRadioButtons">
        <RadioButton x:Name="radio1">Radio1</RadioButton>
        <RadioButton x:Name="radio2">Radio2</RadioButton>
        <RadioButton x:Name="radio3">Radio3</RadioButton>
    </StackPanel>
</GroupBox>
(MyRadioButtons.Children[0] as RadioButton)             // By index
(MyRadioButtons.FindName("radio2") as RadioButton)      // By x:Name attr