APP.xaml.cs
using System.Configuration;WelcomeWindow.xaml
using System.Data;
using System.Diagnostics;
using System.Windows;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// 创建并显示欢迎窗口
var welcomeWindow = new WelcomeWindow();
welcomeWindow.Show();
// 模拟异步初始化操作
await InitializeAsync();
// 延迟 2 秒后显示主窗口并关闭欢迎窗口
await Task.Delay(2000);
Dispatcher.Invoke(() =>
{
var mainWindow = new MainWindow();
mainWindow.Show();
welcomeWindow.Close();
});
}
private async Task InitializeAsync()
{
// 这里可以添加实际的初始化逻辑
await Task.Delay(1000); // 模拟初始化操作
}
}
}
<Window x:Class="WpfApp1.WelcomeWindow"还有一个MainWindow主窗体创建好即可
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="欢迎" Height="200" Width="400"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent">
<Grid>
<Border Background="White" CornerRadius="10" Padding="20">
<TextBlock Text="欢迎使用我们的应用!" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
</Window>
- 本文标题: WPF实现一个带欢迎界面的窗体
- 文章分类:【WinForm/WPF】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.