Reputation: 5070
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:
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);
}
Upvotes: 9
Views: 659
Reputation: 329
have you tried:
protected override void OnInitialized(EventArgs e)
{
while (this.CanFocus) { this.Focus(); WPFWaitForPriority.WaitForPriority(DispatcherPriority.Background); }
base.OnInitialized(e);
}
Upvotes: 0
Reputation: 45
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.
Upvotes: 0
Reputation: 631
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.
Upvotes: 0
Reputation: 2256
How about LoginForm.Activate()
after the splash screen is closed and the LoginForm is displayed?
Upvotes: 0
Reputation: 1224
As per my understanding you can programatically trigger click event once inside constructor .
Upvotes: 0
Reputation: 78
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).
Upvotes: 1
Reputation: 676
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();
}
Upvotes: 0
Reputation: 29673
try this code: Pseudo code:
OnShown
this.focus
I mean. Use diffrent event.
Upvotes: 0