Reputation: 6440
In WPF application, I would like to show window b as a dialog inside window a when window a is loaded. I do this with the following pseudocode:
window a.Loaded += WindowALoaded();
WindowALoaded
{
window b.ShowDialog();
}
This works. However, it displays window b, and window a does not get displayed until I close window b. I would like to display window a completely, and then window b. How would I accomplish this?
Upvotes: 3
Views: 2829
Reputation: 101
You may use the Activated event rather then the Loaded
<Window x:Class="WpfApplication.WindowA"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowA" Height="300" Width="300"
Activated="Window_Activated_1" >
(...)
</Window>
On your code behind:
private void Window_Activated_1(object sender, EventArgs e)
{
WindowB windowB = new WindowB();
windowB.ShowDialog();
}
Also, if don´t wanna use the XAML, this also works perfectly.
public WindowA()
{
this.Activated += Window_Activated_1;
}
Upvotes: 3
Reputation: 1549
Its because in the load event of WindowA, it does a ShowDialog() of WindowB which then haults all code in WindowA until WindowB is closed. If you do just WindowB.Show(), you should probably see WindowA get loaded. You might need to mess with the Window.Focus() and/or the Window.TopMost properties, depending on how you want to windows to be displaying on top of each other.
There also is a Window.ContentRendered event instead of the Window.Loaded event which might help in your solution
Upvotes: 2