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;
        }
        
    }
}
相关推荐
专注VB编程开发20年6 小时前
WPF,Winform,HTML5网页,哪个UI开发速度最快?
大数据·c#·wpf
YANQ66212 小时前
3.1 WPF画折线图、直方图、饼状图
wpf
深漂阿碉12 小时前
WPF自定义日历选择控件
wpf
六点的晨曦12 小时前
WPF的三轴机械手控件动画
wpf
军训猫猫头1 天前
5.浏览本地文件获取路径与文件名称 C#例子 WPF例子
开发语言·c#·wpf
步、步、为营1 天前
.NET + WPF框架开发聊天、网盘、信息发布、视频播放功能
.net·wpf·音视频
code bean2 天前
【WPF实战】MVVM中如何从数据模型反查自定义控件实例(ImageView + Halcon)
wpf
lph19722 天前
ValueConverter转换器WPF
wpf
Sally璐璐2 天前
Memcache核心技术解析与实战应用
运维·wpf·memcached