启动画面的延迟窗口
我正在开发一个项目,我想为其添加一个启动屏幕。我已经在 Stackoverflow 和其他博客以及 MSDN 等上检查过问题,但找不到我正在寻找的解决方案。
我希望我的闪屏
1- 出现并在屏幕上停留 3-4 秒,但同时我希望我的主窗口不出现。当我的启动屏幕完全淡出时,主窗口应该出现。我检查过的许多示例都没有实现这一点。即使我设置了 SplashScreen.Close.(TimeSpan.FromMiliseconds(4000)) MainWindow 仍然紧邻 SplashScreen 的前面或后面。他们说“将图像添加到您的项目中,使其成为构建操作 SplashScreen 或资源,如果您想处理淡出时间,请转到 App.xaml.cs 文件并实现您自己的 Main() 方法并放置您的逻辑。”我已经知道了。它不起作用。
2-如果可能的话,我希望我的闪屏不要慢慢淡出。我希望它突然消失。(如果这对中级开发人员来说不可能或真的很难做到,那没关系。您可以忽略。)
拜托,我想要 C# 代码而不是 Xaml。我的项目基于 WPF 和 .NET 4.0 客户端配置文件。
谢谢。
I am developing a project and I want to add to it a splash screen. I have checked questions here on Stackoverflow and other blogs and MSDN etc. but could not find the solution I am looking for.
I want my SplashScreen,
1- appear and stay on the screen 3-4 seconds but at the same time I want my Main Window NOT TO appear. When my splash screen fades out completely then Main Window should appear. Many of the examples I have checked out do not implement this. Even though I set SplashScreen.Close.(TimeSpan.FromMiliseconds(4000)) MainWindow still apeear immediately front or back of SplashScreen. They say "add an image to your project, make it's Build Action SplashScreen or Resource, if you want to handle fade out time go App.xaml.cs file and implement your own Main() method and put your logic." I know that already. It does not work.
2- If possible I want my splashscreen NOT TO fade out slowly. I want it to disappear suddenly.(if this is not possible or really hard for a intermediate developer to do it, it is ok. you may disregard.)
And please I want C# code not Xaml. My project is based on WPF adn .NET 4.0 client profile.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么不将启动屏幕设置为完全限定的 XAML
并在 App.xaml 中将其设置为 StartupUri:然后在启动窗口的 Load 事件中初始化主窗口 (最好在其他地方,这样当您关闭启动画面时实例就会保留下来)。从这里您还可以指定一个计时器,在 x 秒内关闭并显示主窗口/隐藏启动窗口。
不过,您必须更改应用程序的主窗口行为,否则关闭启动窗口将导致应用程序关闭。
另外,完成后不要忘记丢弃计时器。它是一个
IDisposable
并且将继续触发该方法,除非它被停止。Why don't you make your splash screen a fully qualified XAML
<window>
and in your App.xaml set it up as your StartupUri:Then in your splash window's Load Event you initialize the main window (preferably somewhere else so the instance sticks around when you close the splash). From here you can also specify a timer for x-seconds to go off and show the main window / hide the splash window.
You'll have to change your app's main window behaviour though, otherwise closing the splash window will cause the app to close.
Also don't forget to dispose your timer when you're done. It's an
IDisposable
and will keep firing that method unless it's stopped.有一些答案,但我找到了一个更简单的答案。只需在主窗口的构造函数中使用 Thread.Sleep(int miliSeconds) 方法即可。这将延迟您的应用程序以便稍后打开指定的毫秒数。
There are answers but I find a an easier one. Just use the
Thread.Sleep(int miliSeconds)
method in the main window's constructor. This will delay your app in order to open specified miliseconds later.在 App.xaml.cs 的构造函数中,打开启动屏幕,等待几秒钟,然后关闭,然后再继续应用程序的其余部分。我使用的是 Unity,因此在 Boostrapper 初始化某些服务后,我会在某处关闭启动屏幕。
其中 Bootstrapper.cs 列出如下:
In the constructor of App.xaml.cs open your splash screen, wait for a few seconds, then close before proceeding with rest of the app. I am using Unity, so I close the splash screen somewhere after the Boostrapper has initialized some services.
where Bootstrapper.cs is listed below:
最好的方法和使用 API 是
The best way and using the API is