如何显示进度条/消息,直到页面组件完全加载并显示在屏幕上

本文关键字:显示 组件 屏幕 加载 何显示 消息 | 更新日期: 2023-09-27 18:14:32

我正在开发一个WPF应用程序。我有一个自定义的进度条。这是一个简单的wpf应用程序。在我的应用程序中,我需要显示自定义进度条,直到页面组件加载。我该怎么做呢?

如何显示进度条/消息,直到页面组件完全加载并显示在屏幕上

你也可以使用"BackgroundWorker"来实现。

例子:-http://midnightprogrammer.net/post/Using-Background-Worker-in-C.aspx

你可以这样做....

  //Create a Delegate that matches 
//the Signature of the ProgressBar's SetValue method
private delegate void UpdateProgressBarDelegate(System.Windows.DependencyProperty dp, Object value);
private void Process()
{
    //Configure the ProgressBar
    ProgressBar1.Minimum = 0;
    ProgressBar1.Maximum = short.MaxValue;
    ProgressBar1.Value = 0;
    //Stores the value of the ProgressBar
    double value = 0;
    //Create a new instance of our ProgressBar Delegate that points
    // to the ProgressBar's SetValue method.
    UpdateProgressBarDelegate updatePbDelegate = 
        new UpdateProgressBarDelegate(ProgressBar1.SetValue);
    //Tight Loop: Loop until the ProgressBar.Value reaches the max
    do
    {
        value += 1;
        /*Update the Value of the ProgressBar:
            1) Pass the "updatePbDelegate" delegate
               that points to the ProgressBar1.SetValue method
            2) Set the DispatcherPriority to "Background"
            3) Pass an Object() Array containing the property
               to update (ProgressBar.ValueProperty) and the new value */
        Dispatcher.Invoke(updatePbDelegate, 
            System.Windows.Threading.DispatcherPriority.Background, 
            new object[] { ProgressBar.ValueProperty, value });
    }
    while (ProgressBar1.Value != ProgressBar1.Maximum);
}

请通过这个链接获取更多信息