【问题标题】:Use wait icon when a window is loaded in wpf在 wpf 中加载窗口时使用等待图标
【发布时间】:2013-04-19 18:05:50
【问题描述】:

我正在编写一个 wpf 应用程序,它在单击按钮时从 excel 表中提取数据并加载另一个窗口,其中存在显示结果的数据网格。

现在加载第二个窗口需要 10-12 秒,在此期间我的应用程序会冻结。现在我想要的是显示一个小的圆形带状按钮,它将旋转并显示“请稍候”文本。这将显示在第一个窗口的中心,第一个窗口的其他内容将变暗。

加载第二个窗口后,第一个窗口关闭。 请告诉我该怎么做。

【问题讨论】:

  • 您可能希望为长时间运行的进程使用后台线程,并使用 Dispatcher 来确保您的 UI 得到更新。我实际上写了一篇关于这种情况的相当recent answer,您可能会发现它很有用。
  • 我遇到了同样的问题并解决了。看这个。也许对你有帮助:stackoverflow.com/questions/15416607/…

标签: wpf


【解决方案1】:

问题已解决。非常感谢你的帮助。以下是我使用的代码。

    namespace ScoreX
    {

        public partial class Score : Window
        {
          Applications ap;
          public Score()
          {
            InitializeComponent();
           }

       private void Window_Loaded_1(object sender, RoutedEventArgs e)
         {
        //cb is Circular progress bar
          cbProgress.Visibility = Visibility.Hidden;
         //Some codes
          }

        private void btnProceed_Click(object sender, RoutedEventArgs e)
          {
       //Some lines of Codes
        Thread t1 = new Thread(new ThreadStart(CalculateData));
         t1.SetApartmentState(ApartmentState.STA);
         t1.Start();
         cbProgress.Visibility = Visibility.Visible;

          }

       private void CalculateData()
        {
       //Some codes

        Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
        {

            ap = new Applications();
            this.Close();
            ap.ShowDialog();

        }
        );

    }

【讨论】:

    猜你喜欢
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    相关资源
    最近更新 更多