1.App.xaml
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
SplashScreen spl = new SplashScreen("xxx.jpg");
spl.Show(false);
spl.Close(new TimeSpan(0, 0, 3));//设置关闭启动界面的时间
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(3); // 倒计时3秒
timer.Tick += (s, args) =>
{
timer.Stop();
base.OnStartup(e);
};
timer.Start();
}
private void Application_Startup(object sender, StartupEventArgs e)
{
// 启动主窗口
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
}
2.App.xmal
<Application x:Class="Appliaction类.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Appliaction类"
ShutdownMode="OnLastWindowClose"
Startup="Application_Startup"<!--使用这个事件-->
> <!-- StartupUri="MainWindow.xaml"注释掉 -->
<Application.Resources>
</Application.Resources>
</Application>