Permanent focus on a field - WPF

0

I have an application with several fields, but I would like to focus only on a specific one and not allow it to be withdrawn in any situation. Always focus focus on this field, and if the user tries to pull it off, it blocks and does not allow this action. Possible this task? I work with a DevExpress TextEdit field, similar to the TextBox.

Hugs!

    
asked by anonymous 12.06.2017 / 18:19

2 answers

0

Using the function PreviewLostKeyBoardFocus of 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;
    }
}
    
13.06.2017 / 15:55
1

You can use the LostFocus event of the TextBox.

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

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

    
13.06.2017 / 00:58