In public MainWindow()
I call TestTask3(10000);
. A TextBlock Text is bound to Answer in the XAML. The get
is called and the initial value is displayed. I see the set
call NotifyPropertyChanged. But the get
is not called a second time to get the new value. I also have a button that changes Answer and that does change the TextBlock.
How to fix this or another approach? I want to keep the UI reactive and update some UI elements after a delay.
private int answser = -2;
public int Answer
{
get { return answser; }
set
{
if (answser != value)
{
answser = value;
NotifyPropertyChanged("Answer");
}
}
}
public async void TestTask3(int delay)
{
Debug.WriteLine($"TestTask3");
int answer = -1;
int i = await Task.Run(() =>
{
// … do compute-bound work here
Task.Delay(delay);
answer = -1;
return answer;
});
Debug.WriteLine($"TestTask3 {i}");
Answer = answer;
//return answer;
}