public async void Save(TodoItemViewModel editItem)
 {
     if (Elements.Contains(editItem) == false)
     {
         Elements.Add(editItem);
     }
     await Navigation.ReturnToMain();
 }
        public TodoItemViewModel CreateNew()
        {
            var newItem = new TodoItemViewModel() { ItemName = "New item:" };
            
            NavigateTo(newItem);

            return newItem;
        }
 public async void Save(TodoItemViewModel editItem)
 {
     if (Elements.Contains(editItem) == false)
     {
         Elements.Add(editItem);
     }
     await Navigation.ReturnToMain();
 }
		private TodoItemViewModel[] AddItems(TodoItemViewModel[] result)
		{
			foreach (var item in result)
			{
				Elements.Add(item);
			}

			return result;
		}
        public void Duplicate(TodoItemViewModel item)
        {
            var duplicate = CreateNew();

            duplicate.ItemName    = item.ItemName + " copy";
            duplicate.IsChecked   = item.IsChecked;
            duplicate.Description = item.Description;

            NavigateTo(duplicate);
        }
        public TodoItemViewModel CreateNew()
        {
            var newItem = new TodoItemViewModel()
            {
                ItemName = "New item:"
            };

            NavigateTo(newItem);

            return(newItem);
        }
 internal void ScrollTo(TodoItemViewModel newItem)
 {
     ItemsList.ScrollTo(newItem, ScrollToPosition.End, true);
     ItemsList.SelectedItem = newItem;
 }
 private void OnToggle(TodoItemViewModel item)
 {
     item.Toggle();
 }
        private async void OnDeletePrompt(TodoItemViewModel item)
        {
            var result = await MessageService.ShowYesNo("Confirm delete", "Do you really want to delete it?", "Yes", "No");

            if (result)
            {
                ViewModel.Elements.Remove(item);
            }
        }
        private async void OnShowOptionsCommand(TodoItemViewModel item)
        {
            if (MessageService == null)
            {
                return;
            }

            var selected = await MessageService.PickChoiceFrom(item.AsMenuOptions());
            if (selected != null)
            {
                selected.Command.Execute(item);
            }
        }
 private void SetupCommands(TodoItemViewModel item)
 {
     item.NavigateCommand = new Command(() => ViewModel.NavigateTo(item));
     item.SaveCommand = new Command(() => ViewModel.Save(item) );
     item.CancelEditCommand = new Command(() => ViewModel.CancelEdit(item));
     item.ToggleCommand = new Command(() => OnToggle(item));
     item.ShowOptionsCommand = new Command(() => OnShowOptionsCommand(item));
     item.DeleteCommand = new Command(() => OnDeletePrompt(item));
     item.DuplicateCommand = new Command(() => ViewModel.Duplicate(item));
     item.EditCommand = new Command(() => ViewModel.Edit(item));
 }
		private void SetupCommands(TodoItemViewModel[] elements)
		{
			foreach (var item in elements)
			{
                SetupCommands(item);
			}
		}
        public void Duplicate(TodoItemViewModel item)
        {
            var duplicate = CreateNew();
            duplicate.ItemName = item.ItemName + " copy";
            duplicate.IsChecked = item.IsChecked;
            duplicate.Description = item.Description;

            NavigateTo(duplicate);
        }
 public void NavigateTo(TodoItemViewModel item)
 {
     Navigation.NavigateToAsync(item);
 }
 public async void CancelEdit(TodoItemViewModel item)
 {
     await Navigation.ReturnToMain();
 }
 public void Edit(TodoItemViewModel item)
 {
     NavigateTo(item);
 }
 public async void CancelEdit(TodoItemViewModel item)
 {
     await Navigation.ReturnToMain();
 }
 public void Edit(TodoItemViewModel item)
 {
     NavigateTo(item);
 }
 public void NavigateTo(TodoItemViewModel item)
 {
     Navigation.NavigateToAsync(item);
 }