1.首先定义初始窗体,和主窗体。

  初始窗体(StartWindow) 主窗体(MainWindow):

2.在主窗体界面中,加载初始窗体。注意在线程中操作UI元素需要使用BeginInvoke或者Invoke方法。

  

        StartWindow start;
        public MainWindow()
        {
            InitializeComponent();
            Thread thread = new Thread(LoadResource);
            thread.Start();
            this.Visibility = Visibility.Hidden;
            start = new StartWindow();
            start.closeTheWindows += start_closeTheWindows;
            start.Show();
        }

        /// <summary>
        /// 窗体start关闭之后执行
        /// </summary>
        private void start_closeTheWindows()
        {
            this.Visibility = Visibility.Visible;
        }

        /// <summary>
        /// 执行加载资源等操作
        /// </summary>
        /// <param name="obj"></param>
        private void LoadResource(object obj)
        {
            Thread.Sleep(3000);
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate()
            {
                start.Close();
            });
        }
MainWindow.xaml.cs

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
猜你喜欢
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案