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?
When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.
“WPF would be dead in 2022 because Microsoft doesn't need to be promoting non-mobile and non-cloud technology. But WPF might be alive in that sense if it's the best solution for fulfilling specific customer needs today. Therefore, having a hefty desktop application needs to run on Windows 7 PCs with IE 8.
In WPF UIElement. Visibility has 3 states; Visible/Hidden/Collapsed. If hidden, the control will still affect the layout of surrounding controls, elements that have a Visibility value of Collapsed do not occupy any layout space. You can switch between visible and hidden or collapsed.
Window is the root control that must be used to hold/host other controls (e.g. Button) as container. Page is a control which can be hosted in other container controls like NavigationWindow or Frame. Page control has its own goal to serve like other controls (e.g. Button). Page is to create browser like applications.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With