Search code examples
c#blazormudblazor

MudTable: colored blinking cell


I have such a problem. I have a method that changes the color of a cell.

 private string GetCellStyle(DateTime odbior, DateTime realizacja)
 {
     if (odbior <= realizacja)
     {
        
         return "color:" + animation_color + "; font - size: 2.9rem; font - weight:500; text - align:center;";
     }
     else
     {
         return " font - size: 0.9rem; font - weight:500; text - align:center;";
     }

 }

Calling a method in a table:

 <MudTd  Style="@GetCellStyle(context.odbior, context.realizacja)" DataLabel="Wysyłka">@context.odbior.ToString("dd/MM/yyyy")</MudTd>

I need color animation to change the color to another one after 3 seconds.

Can anyone help?


Solution

  • Have a look at Timer Class.

    With the timer you can set an intervall in which a Method to change animation_color is called.

        Timer timer = new Timer(3000);
        timer.Elapsed += Coloring;
        timer.AutoReset = true;
        timer.Enabled = true;
    

    With Coloring

    private void Coloring(object sender, ElapsedEventArgs e){
        animation_color = $"#{rnd.Next(999999)}";
        StateHasChanged();
    }
    

    https://try.mudblazor.com/snippet/wYGnlPFUHgPtFxeb