WPF Loading

1、启动界面的实现方式

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
      SplashScreen splashScreen = new SplashScreen("pic.jpg");
      splashScreen.Show(true);
      base.OnStartup(e);
    }
}

  

二、页面加载的实现方式

public partial class WindowLoading : Window
{
    public BackgroundWorker backgroundWorker;
    public WindowLoading()
    {
        InitializeComponent();
        backgroundWorker = new BackgroundWorker();
        backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
        Loaded += (s, e) => {
            if (!this.backgroundWorker.IsBusy)
            {
                this.backgroundWorker.RunWorkerAsync();
            }
        };
    }
    void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        this.Close();
    }
}

  

posted @ 2021-10-14 17:35  microsoft-zhcn  阅读(269)  评论(0编辑  收藏  举报