Tomasz
Tomasz

Reputation: 2071

WPF prevent lost focus on TextBox

Is there a way to fully prevent lostFocus from a TextBox?

I would like to prevent any action from app(button clicks, switching focus to other TextBoxes) until I meet some conditions

I have figured out how to prevent switching focus from a TextBox, but this does not help with button clicks/commands:

textBox.PreviewLostKeyboardFocus += (sender, args) =>
{
    if(textBox.Text != "test")
    args.Handled = true;
};

But right now: how to disallow clicking on Buttons? (perfectly - disallow everything until I meet specific conditions)

Upvotes: 0

Views: 600

Answers (1)

Kram
Kram

Reputation: 526

Disable all your button by default. Then in your event, enable button by your conditions.

Upvotes: 1

Related Questions