我正在爲我的WPF應用程序添加一個進度條。我想告訴與生成文件的實時計數一起在進度條上的實時進展情況等產生4/100文件等下面是這兩個動作和任務正在執行這些行動WPF實時進度條
Action Generate = new Action(() =>
{
foreach (string file in Files)
{
//all the logic to generate files
using (var streamWriter = new StreamWriter(newFileName, false, Encoding.Default))
{
foreach (string segment in newFile)
{
streamWriter.WriteLine(segment);
}
filesGenerated++;
//I need to do the second action here
}
}
});
Action ShowProgressBar = new Action(() =>
{
progressBar.Value = filesGenerated
lblProgress.Content = filesGenerated + " File(s) Generated.";
});
Task GenerateTask = Task.Factory.StartNew(() => Generate());
Task ShowProgressBarTask = new Task(ShowProgressBar);
我試圖嵌套的任務,但它不工作。我應該做些什麼來顯示實時進度條。
請使用擴展WPF工具包,它具有BusyIndicator控件元素:CodePlex項目(http://wpftoolkit.codeplex.com/)BusyIndicator控件文件](http://wpftoolkit.codeplex.com/wikipage?title=BusyIndicator&referringTitle=Home) – Rumplin 2011-08-17 12:43:18