Setting Visibility="Hidden" on WPF Window never shows the window again
Solution 1
The window is not loaded until it is shown, as per your code it will not be shown until it is loaded. Obivously this cannot work like that, right?
Solution 2
I was having an issue with this as well and it seems changing the visibility alone on a main window doesn't work as H.B. pointed out. For my case, I wanted to not show the window until it was completely loaded and was able to achieve that by using the property I've linked to here, along with the Show() and Hide() functions on the Window object. System.Windows.Window.ShowActivated
- When initializing the window object don't set visibility to hidden, instead follow the next steps
- Set the ShowActivated property to false
this.ShowActivated = false;
- Call the Hide() function on the window object
this.Hide();
- On your window loaded function from your original example call
this.Show();
It is also possible in some WPF apps for the this
reference not to work as expected, however if this is the case go to the XAML and find the name property of the window. You should be able to ref the window from the code via that name. Ex.
<Window x:Name="MainWindow">
//Code Behind Below
MainWindow.ShowActivated = false;
Related videos on Youtube
Elmo
Updated on June 04, 2022Comments
-
Elmo almost 2 years
I have set the
Visibility
property of the main window toHidden
and added the following inWindow_Loaded
:private void Window_Loaded(object sender, RoutedEventArgs e) { this.Visibility = System.Windows.Visibility.Visible; }
But it doesn't show up the Window. Any specific reason for this?
-
Adi Lester over 12 years@Programmer I don't really see the point of doing something like this anyway, but if you'd set the window's initial visibility to
Collapsed
, theLoaded
event will get fired.