Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Calling method from a view model

$
0
0

I'm looking to implement a countdown timer which displays the count... 10, 9, 8, 7... 1. Then when it hits 0 it fires a command. I'm unsure what the "right" approach for this would be. I'm using Xaml and MVVM. I currently have a class like below:

public class CountDownTimer : View
{
     public Command OnTimeLapsed { get; set; }
     public TimeSpan Duration { get; set; }
     public void Start();
}

But my issue is, I'm unsure what's the best way to call "Start" from my ViewModel.

Another approach I thought I could take is have a setup like this:

public class CountDownTimer
{
     public Action OnTimeLapsed { get; set; }
     public TimeSpan Duration { get; set; }
     public void Start();
     public String TimeDisplay { get; set; }
}

public class CountDownDisplay : View
{
     public CountDownTimer Timer { get; set; }   // obviously this would be bindable
}

Then in my ViewModel I would have

public CountDownTimer Timer { get; set; }

Then in my Xaml I would have

<controls:CountDownTimer Timer={Binding Timer} />

So yeah, just asking about suggested approach for what I'm trying to achieve?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>