Linking the Model and Button

The idea is creating a List collections to store the new To Do Task that being added.

// inside CreatePage.xaml.cs

public List<ToDoItem> toDoItems;
public CreatePage()
{
    toDoItems = new List<ToDoItem>;
    InitializeComponent();
}

Then, we prepare an action when "Save" button being clicked.

private void OnSave(object sender, EventArgs e)
{
    toDoItems.Add(new ToDoItem(
            ToDoEntry.Text,
            Priority.Text,
            SetDueDate(
                Date.Date,
                Time.Time.Hours,
                Time.Time.Minutes,
                Time.Time.Seconds),
            false
        )
    );
}

We create a setDueDate function.

private DateTime SetDueDate(DateTime date, int hour, int minute, int second)
{
    DateTime value = new DateTime(date.Year, date.Month, date.Day, hour, minute, second);
    return value;
}

Now, we clear the value after item being added.

private void Clear()
{
    ToDoEntry.Text = Priority.Text = String.Empty;
    Date.Date = DateTime.Now;
    Time.Time = new TimeSpan(
        DateTime.Now.Hour,
        DateTime.Now.Minute,
        DateTime.Now.Second
    );
}

results matching ""

    No results matching ""