I'm having a problem focusing on a Control
within a Window
in WPF.
On the constructor of the Window
I add a TextBox
as follows:
TextBox tb = new TextBox();
tb.Text = input;
tb.SelectAll();
tb.Focus();
I also call the Focus()
method again on the Window
loaded event.
The problem is that sometimes the window focuses and other times it does not! This is very strange behavior and I was wondering if someone has had the same problem and might be able to give me some guidance.
-- UPDATE
I have found what is causing the problem but no solution yet. I am using WIA to scan a document, this brings up a ProgressBar
which makes my entire application lose focus.
I have tried calling Application.Current.MainWindow.Focus()
but this does not restore focus, any suggestions?