Reputation: 47
I have a simple Tizen .NET application using NUI. I want to create a button that, when clicked, changes its inside text field into a counter that goes down from 5 to 0.
Button button = new Button {
BackgroundColor = Color.Red,
Text = "Click me",
HeightSpecification = 250,
WidthSpecification = 500,
};
button.Clicked += (obj, args) => {
// wait one second, then change text:
// for (int i = 0; i < 6; i++) {
// delay(1000);
// button.Text($"{i}");
// }
};
I need the button text to update every time it changes. However, it does not work with my implementation, and the change only happens after the entire process is finished (so the button's text goes from "Click me" to "5". It never goes "Click me", then "1", then "2", etc.).
My guess is that button.Text property actually does change, but the UI doesn't necessarily get called to update...at least unless the entire delegate function has finished.
I was wondering if there is a special Tizen NUI lifecycle stage that gets called every time a value changes (I am unable to find any in the official documentation) or if I would need to integrate external libraries instead in order to be able to replicate a reactive application?
Upvotes: 0
Views: 128
Reputation: 11
In this case, you may need Timer
.
https://docs.tizen.org/application/dotnet/api/TizenFX/API11/api/Tizen.NUI.Timer.html
var button = new Button()
{
Text = "Hello"
};
var counter = 0;
var timer = new Timer(1000);
timer.Tick += (s, e) => {
button.Text = counter.ToString();
counter++;
return counter < 6;
};
button.Clicked += (s, e) => {
timer.Start();
};
Upvotes: 1