Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClickOnce and inactive main window

My application uses ClickOnce technology for deployment. However I have problem when user starts using the application. The scenario for reproducing the problem is as follows:

  1. User clicks on application's shortcut in order to run the application
  2. ClickOnce's "Launching application" dialog box appears in order to check for updates
  3. "Launching application" dialog box disappears
  4. Splashscreen appears
  5. Main window (login window) appears - however it's not active nor has a focus

Because main window is not active, user has to click on it before he/she can start typing username and password. How can I resolve this problem so the main window is active after it appears? I've tried the following code but it's not working:

protected override void OnInitialized(EventArgs e)
    {
       while (!this.IsFocused) { this.Focus(); WPFWaitForPriority.WaitForPriority(DispatcherPriority.Background); }
       base.OnInitialized(e);
    }
like image 924
niao Avatar asked Aug 10 '11 09:08

niao


1 Answers

Most likely you're giving focus to the splash screen. So when it closes nothing has focus any longer. After closing the form call the Select Method on the control you want to have focus(the username textbox i'm guessing).

Select for Focus

like image 143
GraeningM Avatar answered Oct 14 '22 07:10

GraeningM