.net 在启动时完全隐藏 WPF 窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6690848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:43:52  来源:igfitidea点击:

Completely hide WPF window on startup?

.netwpfwindow

提问by rakete

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!

谢谢!

回答by LukeN

An alternative to H.B.'s method is just to set the Visibilityto hidden and set ShowInTaskbarto false. This still creates the window and lets it do its thing.

HB 方法的替代方法是将 设置Visibility为隐藏并设置ShowInTaskbar为假。这仍然会创建窗口并让它做它的事情。

<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>

回答by H.B.

Don't show the window. By default there is a StartupUridefined in the App.xaml, remove it and override the OnStartupmethod in the code-behind to create a window, just Showand Hideit as you wish.

不要显示窗口。默认情况下,还有一种StartupUri在定义App.xaml,删除和重写OnStartup方法的代码隐藏创建一个窗口,就ShowHide它如你所愿。

回答by Leonard Brünings

Simply don't create a window, just delete the StartupUrifrom App.xaml.

只需不要创建窗口,只需StartupUri从 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.

ShutDownMode="OnExplicitShutdown"如果您的最后一个窗口关闭,将应用程序设置为这将防止您的应用程序关闭可能会有所帮助。