Reputation: 65
I have a bunch of programmatically-created RadioButtons that are displayed in a StackPanel.
I want to use some on-screen buttons or the arrow keys to navigate these RadioButtons, and set the IsChecked property to True when landing on them.
I'm just not sure how to reference these RadioButtons?
Any direction would be appreciated, thanks!
Upvotes: 0
Views: 74
Reputation: 65534
When you dynamically add the controls you will want to store them in a private member variable for reference, eg Private ctrls As New List<Controls>()
and then in the Key_Down event set the ctrl[0].IsChecked.
Private Sub Window_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.Key = Key.Down Then
Dim ctrlIndex As Integer = ControlIdWithFocus()
ctrls(ctrlIndex).IsChecked = True
End If
End Sub
Alternatively you could iterate through the Me.Controls collection, although that will contain all the controls not just the Radio buttons.
Upvotes: 1