状态更改和响应式组件适用于Tizen .NET NUI应用程序吗?

huangapple go评论96阅读模式
英文:

State changes and reactive components for Tizen .NET NUI apps?

问题

我有一个使用NUI的简单Tizen .NET应用程序。我想创建一个按钮,当点击时,将其内部文本字段更改为从5减少到0的计数器。

Button button = new Button {
    BackgroundColor = Color.Red,
    Text = "点击我",
    HeightSpecification = 250,
    WidthSpecification = 500,
};

button.Clicked += (obj, args) => {
    // 等待一秒,然后更改文本:
    // for (int i = 0; i < 6; i++) {
    //     delay(1000);
    //     button.Text($"{i}");
    // }
};

我需要按钮文本在每次更改时更新。但是,我的实现无法正常工作,只有在整个过程完成后才发生更改(因此按钮的文本从"点击我"变为"5",它从不是"点击我",然后是"1",然后是"2",等等)。

我猜测button.Text属性实际上会更改,但UI不一定会被调用以进行更新...至少除非整个委托函数已经完成。

我想知道是否有一个特殊的Tizen NUI生命周期阶段,在每次值更改时都会被调用(我无法在官方文档中找到任何内容),或者是否需要集成外部库以复制响应式应用程序?

英文:

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 = &quot;Click me&quot;,
    HeightSpecification = 250,
    WidthSpecification = 500,
};

button.Clicked += (obj, args) =&gt; {
    // wait one second, then change text:
    // for (int i = 0; i &lt; 6; i++) {
    //     delay(1000);
    //     button.Text($&quot;{i}&quot;);
    // }
};

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?

答案1

得分: 1

在这种情况下,您可能需要使用 Timer
https://docs.tizen.org/application/dotnet/api/TizenFX/API11/api/Tizen.NUI.Timer.html

var button = new Button()
{
    Text = "你好"
};

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();
};

英文:

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 = &quot;Hello&quot;
};

var counter = 0;
var timer = new Timer(1000);
timer.Tick += (s, e) =&gt; {
    button.Text = counter.ToString();
    counter++;
    return counter &lt; 6;
};

button.Clicked += (s, e) =&gt; {
    timer.Start();
};

huangapple
  • 本文由 发表于 2023年8月9日 09:50:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864092-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定