public class Page2ViewModel : ViewModelBase
{
public Page2ViewModel(INavigationService navigationService)
: base(navigationService)
{
AddItem = new DelegateCommand<string>(OnAddItem);
GotoPage1 = new DelegateCommand<string>(OnGotoPage2);
for ( int a = 0; a < 5; a++)
{
Items _Item = new Items();
_Number++;
_Item.Number = _Number.ToString();
_Item.Name = "Constructor name";
ItemBucket.Add(_Item);
}
timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Start();
timer.Elapsed += OnTimedEvent;
timer.AutoReset = true;
timer.Enabled = true;
}
private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
Items _Item = new Items();
Device.BeginInvokeOnMainThread(async () =>
{
await Task.Delay(200);
_Number++;
_Item.Number = _Number.ToString();
_Item.Name = "Timer name";
ItemBucket.Add(_Item);
});
}
} |