WPF demo:全屏加载界面

xml 复制代码
<Window>

    <Grid x:Name="LoadingLayer" Background="#FF0A0A0A" >
        <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
            <ProgressBar x:Name="LoadingProgress" Visibility="Hidden" Width="400" Height="20" Margin="0,0,0,20" IsIndeterminate="True" Foreground="#FF4A90E2" ></ProgressBar>
        	<TextBlock x:Name="LoadingText" Text="" HorizontalAlignment="Center" Foreground="#CCFFFFFF" FontSize="18" FontWeight="SemiBlod"></TextBlock>
        </StackPanel>
    </Grid>

</Window>
csharp 复制代码
namespace project
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.Topmost = true;
            this.Left = 0.0;
            this.Top = 0.0;
            this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
            this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
            this.WindowState = System.Windows.WindowState.Normal;
            this.WindowStyle = System.Windows.WindowStyle.None;
            this.ResizeMode = System.Windows.ResizeMode.NoResize;
			this.Loaded += ShowWindow;
        }
        
        protected override void OnKeyDown(RoutedEventArgs e)
        {
            if(e.Key == Key.Escape)
            {
                Application.current.ShutDown();
            }
            base.OnKeyDown(e);
        }
        
        private async Task Wait()
        {
            await Task.Delay(2000);
        }
        
        private async void ShowWindow(object sender, RoutedEventArgs e)
        {
            await Wait();
            LoadingProgress.Visibility=Visibility.Visible;
            await LoadingRes();
        }
        
        private async Task LoadingRes()
        {
            for(int i=0;i<100;i++)
            {
                await Task.Delay(60);
                if(i<60)
                    LoadingText = "正在初始化核心模块...";
                else if(i<90)
                    LoadingText = "正在加载用户数据...";
                else
                    LoadingText = "正在创建游戏场景...";
            }
            LoadingProgress.Visibility=Visibility.Hidden;
            LoadingText.Visibility = Visibility.Hidden;
        }
        
    }
}
相关推荐
Aevget1 小时前
界面控件DevExpress WPF v25.1新版亮点:PDF Viewer功能全新升级
pdf·wpf·界面控件·devexpress·ui开发
5***a9752 天前
后端配置中心选型,Nacos与Apollo
wpf
·心猿意码·2 天前
WPF转换器机制
wpf
她说彩礼65万2 天前
WPF命令
wpf
玖笙&2 天前
✨WPF编程进阶【7.3】集成动画(附源码)
c++·c#·wpf·visual studio
ifeng09182 天前
鸿蒙分布式调试挑战:跨设备数据流转与连接稳定性
分布式·wpf·harmonyos
Macbethad2 天前
如何使用WPF做工控主页
wpf
Aevget3 天前
DevExpress WPF中文教程:Data Grid - Service(服务)示例
wpf·界面控件·devexpress·ui开发
Macbethad3 天前
WPF工控软件的设计方案
wpf
Macbethad5 天前
使用WPF编写一个读取串口的程序
wpf