WPF,单击TextBox应检查RadioButton

时间:2013-01-29 10:21:47

标签: c# wpf textbox radio-button

我在RadioButton内有TextBoxStackPanel,如下所示:

  <StackPanel Orientation="Horizontal">
        <RadioButton x:Name="rbSelectedQuantity" GroupName="CardQuantity"
          FontSize="14" Margin="5"
          Content="Selected Quantity">
        </RadioButton>

        <TextBox x:Name="txtSelectedQuantity" Width="50" Margin="5" TextAlignment="Right"
        Text="0"></TextBox>
  </StackPanel>

以下是我的场景:如果我在TextBox内部单击,应该自动检查我的单选按钮。

我该怎么做?

1 个答案:

答案 0 :(得分:3)

处理TextBox的GotFocus事件,并将RadioButton IsChecked属性设置为True

private void txtSelectedQuantity_GotFocus(object sender, RoutedEventArgs e)
    {
        rbSelectedQuantity.IsChecked = True;
    }