Tizen .NET NUI应用程序的状态变化和响应式组件是什么?

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

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

问题

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

Button button = new Button {
    BackgroundColor = Color.Red,
    Text = "Click me",
    HeightSpecification = 250,
    WidthSpecification = 500,
};

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

我需要按钮文本在每次更改时更新。然而,我的实现方式不起作用,只有在整个过程完成后才发生更改(所以按钮的文本从"Click me"变为"5",而不是"Click me",然后是"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 = "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();
};

英文:

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.html
匿名

发表评论

匿名网友

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

确定