1

I have a some number that changing fast enough while runtime. I need to show it on the WPF Window. I've tried few ways, but no success. If I bind interesting number to the property, it's shows only last value, but no in process of changing. If I set text directly - result is the same. But if I change number and set window's Title property, the result is visible.

For i As Integer = 0 To 1000
   txt.Text = "count=" & i.ToString() 'txt is the name of TextBlock control
Next

For i As Integer = 0 To 1000
   MyProperty = "count=" & i.ToString() 'MyProperty calls INotifyPropertyChanged event
Next

For i As Integer = 0 To 1000
   Me.Title = "count=" & i.ToString() 'this is works!!! but why?
Next

I know some more variants: update text by timer and update it by Window.OnRender event. But it's interesting, why case with Title is works and others - not. And what is the best and correct way to show fast changing values on GUI?

Aave
  • 548
  • 1
  • 5
  • 15
  • Never call Thread.Sleep in the UI thread. It will simply block that thread, and the UI won't do anything. – Clemens Apr 12 '19 at 20:31
  • @Clemens it's just an example, in real application this is a small job that application do. – Aave Apr 13 '19 at 01:58
  • @Clemens and that answer is absolutely not for my case. I don't understand the decision to close my question... – Aave Apr 13 '19 at 02:04
  • No idea why it works for the Title property. In general, loops like yours block the UI during their execution. The UI won't do anything while the loop executes. You need to add a delay that allows the UI to update, e.g. `await Task.Delay(30)`. – Clemens Apr 13 '19 at 06:32

0 Answers0