我在一个 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>
这是我的场景:如果我在文本框中单击,我的单选按钮应该会自动选中。
我应该怎么做?
最佳答案
处理 TextBox 的 GotFocus
事件并将 RadioButton
IsChecked
属性设置为 True
private void txtSelectedQuantity_GotFocus(object sender, RoutedEventArgs e)
{
rbSelectedQuantity.IsChecked = True;
}
关于c# - WPF,单击 TextBox 应检查 RadioButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14580589/