+Update
Hi, @João Coelho , you can override the OnInitialized method. It will execute when page load.
@code {
private int state = 0;
private string readBg { get; set; }
private string greenBg { get; set; }
private string blueBg { get; set; }
protected override void OnInitialized() // = On PageLoad
{
readBg = "red";
greenBg = "green";
blueBg = "blue";
}
}
Hi, @João Coelho ,
You could try as below.
@code {
private int state = 0;
private string Background { get; set; } = "red";
private void ChangeValues()
{
state++;
if (state % 3 == 0)
Background = "red";
if (state %3 == 1)
Background = "green";
if (state % 3 == 2)
Background = "yellow";
}
}
The screenshots of test:
------
If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Michael Wang