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;
        }
        
    }
}
相关推荐
张人玉1 天前
WPF 触发器详解:定义、种类与示例
c#·wpf·1024程序员节·布局控件
rollingman1 天前
WPF ComboBox 样式
wpf·combobox·textbox
Aevget1 天前
DevExpress WPF中文教程:Data Grid - 如何使用虚拟源?(三)
wpf·界面控件·devexpress·ui开发·1024程序员节
张人玉1 天前
WPF 核心概念笔记(补充示例)
c#·wpf·1024程序员节·布局控件
亦陈不染2 天前
WPF-MVVM的简单入门(第一个MVVM程序)
wpf
FuckPatience2 天前
WPF TreeView 条目右键命令 ContextMenu按钮绑定命令
wpf
The 旺2 天前
【案例实战】HarmonyOS分布式购物车:多设备无缝协同的电商体验
分布式·wpf·harmonyos
FuckPatience2 天前
WPF MVVM下 ItemsControl条目命令绑定传参
wpf
加号33 天前
【WPF】自定义颜色拾取器
wpf·自定义颜色拾取器
张人玉3 天前
WPF 常用样式属性及示例笔记
笔记·wpf