I am doing a WPF application with a virtual keyboard .As mentionned in the picture, there is two textbox pseudo
and password
and i'd like to enter their values using the virtual keyboard.
The problem is how to know that the cursor is in the first field or in the second one or out. I tried isfocused
but it didn't give a result.
So how can i do this task?
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;
}
}