如何在WPF中逐个显示标签上的某些文件名

时间:2016-06-18 11:43:51

标签: c# wpf

我的代码:

//Array with number of files
string[] A = Directory.GetFiles("C:\\Users\\ggg\\AppData\\Local\\Google\\Chrome\\User Data\\Default", "*.*", SearchOption.AllDirectories);

for (int i = 0; i < A.Length; i++)
{
    Label files = ((MainWindow)System.Windows.Application.Current.MainWindow)._pnlScanResults.FindName("lblFiles") as Label;
    files.Content = cGlobal.filesArray[i].ToString();
    //need some time to see file name one by one on label.....how ??
}

1 个答案:

答案 0 :(得分:1)

Lbl是显示文件名的Label

            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                for (int i = 0; i < A.Length - 1; i++)
                {
                    System.Threading.Thread.Sleep(1000);
                    Lbl.Dispatcher.Invoke(() => { Lbl.Content = i + " : " + A[i]; });
                }
            });