开发者

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(); WPFWaitForPriorit开发者_运维知识库y.WaitForPriority(DispatcherPriority.Background); }
       base.OnInitialized(e);
    }


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


try this code: Pseudo code:

OnShown
this.focus

I mean. Use diffrent event.


I have a WPF / ClickOnce application and don't have the same problem. I don't use the StartupUri of App.xaml, I manually show the login window instead as follows in App.xaml.cs:

protected override void OnStartup(StartupEventArgs e)
    {
        this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
        this.Exit += new ExitEventHandler(App_Exit);         
        base.OnStartup(e);
        ShowLogin();
    }

    private MainWindow _mainWindow;

    private void ShowLogin()
    {            

        _mainWindow = new MainWindow(delegate()
        {
            //.......
        });

        _mainWindow.Closed += new EventHandler(_mainWindow_Closed);

        this.MainWindow = _mainWindow;
        this.MainWindow.Show();            
    }


As per my understanding you can programatically trigger click event once inside constructor .


How about LoginForm.Activate() after the splash screen is closed and the LoginForm is displayed?


Maybe try to get focus on TextBox on that form. Login name for example.

I think OnInitialized event may be too early. OnShown should be good.


Are you using Visual Studio? I know if you go to the form properties under the project tab, you can specify the start up object. Perhaps you can specify your main form and the splashscreen can load in front of it.


have you tried:

protected override void OnInitialized(EventArgs e)
{
   while (this.CanFocus) { this.Focus(); WPFWaitForPriority.WaitForPriority(DispatcherPriority.Background); }
   base.OnInitialized(e);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜