title: How to get selected radio button in group via c#
body: <p>How to get the index of the selected Radiobutton control that is located inside a stackpanel (parent container) than border than radio button via c#?</p>
  
  <p>here is what i am got after searching and trying </p>
  
  <pre><code> for (int i = 0; i &lt; this.selective.Children.Count; i++)
              {
  
                  if (this.selective.Children[i].GetType().Name == "RadioButton")
                  {
                      RadioButton radio = (RadioButton)this.selective.Children[i];
                      if ((bool)radio.IsChecked)
                      {
                          //get checked indes name
                     }
                 }
            }
  </code></pre>
  
  <p>but here i am having radio button inside border so how to achieve the same </p>
  
  <p>here is my xaml</p>
  
  <pre><code>  &lt;StackPanel Visibility="Collapsed" x:Name="selective" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="462"   &gt;
  
                      &lt;Border  Margin="20,0,20,0" Grid.Row="2" BorderThickness="2" BorderBrush="Black" &gt;
                          &lt;RadioButton GroupName="main1" x:Name="radio1"   Foreground="#FF030303"   Background="#FF0075A9" /&gt;
                      &lt;/Border&gt;
                      &lt;Border Margin="20,0,20,0" Grid.Row="2" BorderThickness="2" BorderBrush="Black" &gt;
  
                          &lt;RadioButton GroupName="main1" x:Name="radio2"   Foreground="#FF030303"   Background="#FF0075A9"  /&gt;
                      &lt;/Border&gt;
      ....
  </code></pre>
  
  <p>so how to know which is checked ?</p>