【问题标题】:How to show a progress in a TextBlock and ProgressBar?如何在 TextBlock 和 ProgressBar 中显示进度?
【发布时间】:2016-09-11 14:26:20
【问题描述】:

我想显示我的 Excel 阅读程序的进度。 这里有一些代码:

public void ReadExcel()
    {
    //Do something (get Excel File...)

    txtProgress.Text += "Start";        

    int rows = exRng.Rows.Count;
    int column = exRng.Columns.Count;

    progProgress.Maximum = rows;//ProgressBar
    txtProgress.Text += "Start";//TextBlock

    for (int i = 1; i <= rows; i++)
    {
        progProgress.Value = i;         
        //Do something
        txtProgress.Text += "\n " + Name + " was created";
    }
}

ProgressBar 最大值是 excel 文件中的行数。在每个循环之后,TextBlock 应该显示该名称已创建。 ProgressBar 值应显示进度。

我的窗口如下所示: Window with a Textblock at the top and a ProgressBar at the bottom

但窗口只显示 Excel 读取的结束。它不会刷新 TextBlock 或 ProgressBar。我只看到空窗口,最后是这个窗口:End of Progress

有人可以帮助我吗?谢谢

【问题讨论】:

    标签: c# wpf excel progress-bar


    【解决方案1】:

    您应该使用 backgroundWorker 来实现这一点。 非常相似的例子详细讨论here

    询问,如果您在实施时遇到困难。

    【讨论】:

    • 我需要帮助来实现,你能帮帮我吗?
    • 我的Skype:uralniti
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多