Share via


How to: Create a RadioButton

This example shows how to create a RadioButton.

The following example creates RadioButton controls by using Extensible Application Markup Language (XAML). It also provides a code-behind file, available in more than one programming language, to handle the Click event.

Example

<StackPanel>      
    <RadioButton Name="rb1" Checked="WriteText2">Yes</RadioButton>
    <RadioButton Name="rb2" Checked="WriteText2">No</RadioButton>
    <RadioButton Name="rb3" Checked="WriteText2">No opinion</RadioButton>
</StackPanel>
        void WriteText2(object sender, RoutedEventArgs e)
{
    RadioButton li = (sender as RadioButton);
        txtb.Text = "You clicked " + li.Content.ToString() + ".";
        }        
Public Sub WriteText2(ByVal Sender As Object, ByVal e As RoutedEventArgs)

    Dim li As RadioButton = CType(Sender, RadioButton)
    txtb.Text = "You clicked " + li.Content.ToString() + "."

End Sub

For the complete sample, see RadioButton Sample.

See Also

Reference

ToggleButton

Concepts

RadioButton Overview