//File:Window.xaml.vb
Imports System
Imports System.Linq
Imports System.Windows
Imports System.Windows.Controls
Namespace WpfApplication1
Public Partial Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim radioButton As RadioButton = Nothing
radioButton = GetCheckedRadioButton(spLeftContainer.Children, "Group1")
If radioButton Is Nothing Then
radioButton = GetCheckedRadioButton(spRightContainer.Children, "Group1")
End If
MessageBox.Show(Convert.ToString(radioButton.Content) & " checked.", Title)
End Sub
Private Function GetCheckedRadioButton(children As UIElementCollection, groupName As [String]) As RadioButton
Return children.OfType(Of RadioButton)().FirstOrDefault(Function(rb) rb.IsChecked = True AndAlso rb.GroupName = groupName)
End Function
Private Sub RadioButton_Checked(sender As Object, e As RoutedEventArgs)
If Not Me.IsInitialized Then
Return
End If
Dim radioButton As RadioButton = TryCast(e.OriginalSource, RadioButton)
If radioButton IsNot Nothing Then
MessageBox.Show(Convert.ToString(radioButton.Content) & " checked.", Title)
End If
End Sub
End Class
End Namespace