Permanent focus on a field - WPF

Asked

Viewed 132 times

0

I have an application with several fields, but I would like to leave the focus only on one specific and not allow the withdrawal of the same in any situation. Force the focus always in this field, and if the user tries to withdraw, it blocks and does not allow this action. Possible that task? Working with a Textedit field from Devexpress, similar to Textbox.

Hug!

2 answers

1

You can use the event LostFocus textbox.

private void textBox1_LostFocus(object sender, EventArgs e)
{
    this.ActiveControl = textBox1;
}

Note that I used the name textBox1 only as an example.

  • I work with a Usercontrol, I don’t have this Activecontrol. I also tried textBox1.Focus(), but it goes into an infinite loop.

  • I’ve come up with another solution... I’ll put it

  • 1

    Good, I hope I helped.

0


Using the function PreviewLostKeyBoardFocus textedit.

private void textNome_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
    if (e.NewFocus != null && !LayoutHelper.IsChildElementEx((DependencyObject)sender, (DependencyObject)e.NewFocus))
    {
        textNome.Focus();
        Keyboard.Focus(textNome);
        e.Handled = true;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.