Unable to show dynamic timer countdown in RadGridView cell

1 Answer 346 Views
GridView
Pribadi
Top achievements
Rank 1
Iron
Iron
Pribadi asked on 18 Aug 2022, 06:19 AM

Hi,

I am unable to show the dynamic timer countdown in the GridView cell. 

can you please help me with the proper method. Refer to the attached video for more details.

 

Thank you

 

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 18 Aug 2022, 01:35 PM

Hello Pribadi,

I have attached a sample project, which shows one approach for achieving this functionality.

In the attached application, the countdown is represented by a property of the type TimeSpan, whose value is updated each second by a DispatcherTimer class instance.

The following code snippets show this approach's implementation:

public class ItemModel : ViewModelBase
{
    private TimeSpan countdown;
    public TimeSpan Countdown
    {
        get { return this.countdown; }
        set { this.countdown = value; this.OnPropertyChanged(nameof(this.Countdown)); }
    }
}
public class MainViewModel
{
    private DispatcherTimer dispatcherTimer;

    public MainViewModel()
    {
        this.ItemModels = new ObservableCollection<ItemModel>()
        {
            new ItemModel()
            {
                Countdown = new TimeSpan(0, 0, 60),
            }
        };

        this.ItemModel = this.ItemModels[0];

        this.dispatcherTimer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, OnIntervalElapsed, Application.Current.Dispatcher);
        this.dispatcherTimer.Stop();
    }

    public ItemModel ItemModel { get; set; }
    public ObservableCollection<ItemModel> ItemModels { get; set; }

    private void OnIntervalElapsed(object sender, EventArgs e)
    {
        this.ItemModel.Countdown = this.ItemModel.Countdown.Add(TimeSpan.FromSeconds(-1));

        if (this.ItemModel.Countdown <= TimeSpan.Zero)
        {
            this.dispatcherTimer.Stop();
        }
    }
}

The produced result is as follows:

Could you give the sample project a try?

Regards,
Stenly
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Tags
GridView
Asked by
Pribadi
Top achievements
Rank 1
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or