Reputation: 2852
ShowDialog
then unhide the first window.When I do that:
this.Hide();
var window2 = new Window2();
window2.ShowDialog();
this.Show();
The first window open as a blank and empty window.
What's wrong in this technique?
When I do that:
var window2 = new Window2();
Visibility = Visibility.Collapsed;
window2.ShowDialog();
Visibility = Visibility.Visible;
The first window exits then the application.
What's wrong in this technique too?
Upvotes: 11
Views: 41804
Reputation: 31
This code solved my problem
var window = new Window()
{
WindowStyle = WindowStyle.Hidden,
Height = 0;
Width = 0;
};
window.Show();
Upvotes: 0
Reputation: 9867
Do this instead:
this.Visibility = Visibility.Collapsed;
...
this.Visibility = Visibility.Visible;
Also, I saw your comment above that this doesn't work. However, I started a new WPF project, did this, built and ran it. It works.
Note that there are no errors.
Upvotes: 17
Reputation: 475
Check your Application.Current.ShutdownMode
. Closing the window you assign to Application.Current.MainWindow
will cause the application to shutdown, if Application.Current.ShutdownMode
is set to OnMainWindowClose
. In your case I would set it to OnExplicitShutdown
. You can see the default values being set in app.xaml
of your WPF application project.
Upvotes: 2
Reputation: 31
foreach (Window window in App.Current.Windows)
{
if (!window.IsActive)
{
window.Show();
}
}
Works fine for me
Upvotes: 3
Reputation: 7847
In my case next code worked out:
new HiddenWindow
{
WindowStyle = WindowStyle.None,
AllowsTransparency = true,
Opacity = 0.0
}.Show();
Upvotes: 3
Reputation: 12315
Window2 window2 = new Window2();
this.Visibility = Visibility.Collapsed;
window2.ShowDialog();
this.Visibility = Visibility.Visible;
Upvotes: 3