Reputation: 3041
I want that my window is completely hidden on the startup. No window, no entry in the taskbar. The user doesn't see, the application is started.
How can I realize that?
Thank you!
Upvotes: 41
Views: 48346
Reputation: 71
If a window should be created but not displayed, just don't show it. Set '-s' command line argument to run in silent mode.
protected override void OnStartup(StartupEventArgs e)
{
// Get the command line arguments
string[] args = Environment.GetCommandLineArgs();
var silentMode = args.Count() > 1 && args[1].ToLower().Equals("-s");
// If silent mode is enabled, the window is not displayed
var mainWindow = new MainWindow();
if (!silentMode) mainWindow.Show();
}
Upvotes: 0
Reputation: 26
My requirement: Start a process to show a window, and embed it into a wpf control. The window must be loaded normally, trigger initialized/loaded events, then run as child window in control.
My solution: Set the window width and height to 1, after loaded, resize it to normal size. The window will be shown in short time, almost 1 second. User will not notice it.
Upvotes: 0
Reputation: 13222
Simply don't create a window, just delete the StartupUri
from App.xaml.
It might be helpful to set the Application to ShutDownMode="OnExplicitShutdown"
this will prevent that your application shuts down if your last window was closed.
Upvotes: 21
Reputation: 1738
An alternative to H.B.'s method is just to set the Visibility
to hidden and set ShowInTaskbar
to false. This still creates the window and lets it do its thing.
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" ShowInTaskbar="False" Visibility="Hidden">
<Grid>
</Grid>
</Window>
Upvotes: 50
Reputation: 184441
Don't show the window. By default there is a StartupUri
defined in the App.xaml
, remove it and override the OnStartup
method in the code-behind to create a window, just Show
and Hide
it as you wish.
Upvotes: 45