WPF C# Tutorial

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" SizeToContent="Height" Width="300">
    
        
            
            
        

        
            
        

        
        
        
            
            
            
            
            
            
                                     Margin="5" Name="rbnTwoA" />
            
            
        
        
            
            
            
        
                        Margin="10" MaxHeight="25" Click="Button_Click" />
    

//File:Window.xaml.cs
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RadioButton radioButton = null;
            radioButton = GetCheckedRadioButton(spLeftContainer.Children, "Group1");
            if (radioButton == null)
            {
                radioButton = GetCheckedRadioButton(spRightContainer.Children, "Group1");
            }
            MessageBox.Show(radioButton.Content + " checked.", Title);
        }
        private RadioButton GetCheckedRadioButton(UIElementCollection children, String groupName)
        {
            return children.OfType().FirstOrDefault( rb => rb.IsChecked == true && rb.GroupName == groupName);
        }
        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (!this.IsInitialized) return;
            RadioButton radioButton = e.OriginalSource as RadioButton;
            if (radioButton != null)
            {
                MessageBox.Show(radioButton.Content + " checked.", Title);
            }
        }
    }
}