Reputation: 10758
My app's main UI is in MainWindow.xaml.
Firstly - what is causing this to be the window the application opens on startup. It does not appear to be defined as a "starup object" and there does not appear to be any code that specifically launches this window.
I can make my login window appear when the app starts by in the loaded event of MainWindow.xaml defining a new "login.xaml" and telling it to show as a dialog. However, if I do this then MainWindow does not appear until Login has been closed.
What I want to achieve is when my app starts, the MainWindow appears and then on top of that the Login window is displayed modally.
How can this be done?
Upvotes: 0
Views: 547
Reputation: 8986
In app.xaml the following line defines the startup window, you can change it if you want
StartupUri="MainWindowView.xaml"
If you are following MVVM you can bind a command to the windows loaded event using System.Windows.Interactivity (otherwise simply create an event handler as the others have suggested)
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding MyICommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
Upvotes: 0
Reputation: 184296
The startup of the MainWindow
is defined in App.xaml
by default when creating a project in VS:
<Application ...
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Creating the dialogue in the Loaded
event should work, just don't do it in the constructor where it is not yet loaded.
Loaded="Window_Loaded"
private void Window_Loaded(object sender, RoutedEventArgs e)
{
new LoginDialogue().ShowDialog();
}
Upvotes: 3
Reputation: 137108
One way could be to add a Loaded
event handler to your main window and in that display the login window:
this.Loaded += LoadedEventHander;
void LoadedEventHander(object sender, RoutedEventArgs e)
{
// Show Login.xaml here.
}
Upvotes: 1