我正在使用虚拟键盘做一个 WPF 应用程序。如图中提到的,有两个文本框 pseudo
,password
我想使用虚拟键盘输入它们的值。
问题是如何知道光标是在第一个字段中还是在第二个字段中或外面。我试过isfocused
了,但没有给出结果。
那么我该怎么做这个任务呢?
public partial class Authentification : Window
{
public TextBox numero = new TextBox();
bool isPseudoFocused = false;
bool isPasswordFocused = false;
public Authentification()
{
InitializeComponent();
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
if (Keyboard.FocusedElement == pseudo)
MessageBox.Show("hhhh");
}
private void un_Click(object sender, RoutedEvent e)
{
if (isPseudoFocused) pseudo.Text += "1";
if (isPasswordFocused) password.Text += "1";
}
private void pseudo_FocusableChanged(Object sender, DependencyPropertyChangedEventArgs e)
{
MessageBox.Show("pseudo");
isPseudoFocused = true;
isPasswordFocused = false;
}
private void password_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e)
{
MessageBox.Show("password");
isPseudoFocused = false;
isPasswordFocused = true;
}
}