【问题标题】:WPF , Clicking on TextBox should check the RadioButtonWPF ,单击 TextBox 应检查 RadioButton
【发布时间】:2013-01-12 21:16:52
【问题描述】:

我在一个StackPanel 中有一个RadioButton 和一个TextBox,如下所示:

  <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>

这是我的场景:如果我在文本框内单击,我的单选按钮应该会被自动选中。

我应该怎么做?

【问题讨论】:

    标签: c# wpf textbox radio-button


    【解决方案1】:

    处理文本框的GotFocus 事件并将RadioButton IsChecked 属性设置为True

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

    【讨论】:

      猜你喜欢
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 2017-12-02
      • 2018-08-20
      • 2013-06-17
      • 2012-01-06
      相关资源
      最近更新 更多