How do I refresh visual control properties (TextBlock.text) set inside a loop?

前端 未结 5 952
醉梦人生
醉梦人生 2020-12-14 04:08

With each loop iteration, I want to visually update the text of a textblock. My problem is that the WPF window or control does not visually refresh until the loop is complet

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 04:28

    for (int i = 0; i < 50; i++)
    {
        System.Threading.Thread.Sleep(100);
        myTextBlock.Text = i.ToString();                
    }
    

    Running the above code inside a background worker component and using a binding updatesourcetrigeer as propertychanged will reflect the changes immediately in the UI control.

提交回复
热议问题