Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF,单击文本框应选中单选按钮_C#_Wpf_Textbox_Radio Button - Fatal编程技术网

C# WPF,单击文本框应选中单选按钮

C# WPF,单击文本框应选中单选按钮,c#,wpf,textbox,radio-button,C#,Wpf,Textbox,Radio Button,我有一个单选按钮和一个文本框在一个堆栈面板内,如下所示: <StackPanel Orientation="Horizontal"> <RadioButton x:Name="rbSelectedQuantity" GroupName="CardQuantity" FontSize="14" Margin="5" Content="Selected Quantity"> </RadioBut

我有一个
单选按钮
和一个
文本框
在一个
堆栈面板
内,如下所示:

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

下面是我的场景:如果我在文本框内单击,我的单选按钮将自动选中


我应该怎么做?

处理文本框的
GotFocus
事件,并将
单选按钮
IsChecked
属性设置为
True

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