你好,
我们可以罗列出一些可输入元素,如果是可输入的,把系统中用于标识是否屏蔽的变量设置为false,当失去焦点时,可以重置为true.
以下的例子实现的功能是:当焦点在第一个TextBox时,不启用屏蔽功能,当失去焦点到别的控件上,就会屏蔽数字输入:
private Boolean isBlock = false;
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
isBlock = false;
}
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
isBlock = true;
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (isBlock == true)
e.Handled = (Convert.ToChar(e.Key) < '0' || Convert.ToChar(e.Key) > '9') ;
}
<StackPanel>
<TextBox Text="TextBox" Height="30" GotFocus="TextBox_GotFocus" LostFocus="TextBox_LostFocus" />
<TextBlock Text="TextBlock" Height="30" Background="AliceBlue" />
<Button Content="Button1" />
<TextBox />
</StackPanel>
截图:

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.