/// <summary> /// Deletes the given checkbox item. /// </summary> /// <param name="checkbox"></param> private void DeleteItems(object checkboxes) { IList boxes = (IList)checkboxes; if (boxes == null) { return; } List <CheckBox> convertedBoxes = new List <CheckBox>(boxes.Cast <CheckBox>()); // Loop around removing the checkboxes selected, but not if they're text is the default text. foreach (CheckBox box in convertedBoxes) { if (box.Content.ToString() == DefaultTODO) { continue; } CheckListList.Remove(box); } DataDealer.WriteChecklistData(CheckListItems); // Make sure that there's always a default todo if (CheckListList.Count <= 0) { CheckListList.Add(MakeCheckBoxForItem(DefaultTODO)); } string[] itemsDeleted = convertedBoxes.Select(checkbox => checkbox.Content.ToString()).ToList().ToArray(); // Fire the event. ItemsDeleted?.Invoke(this, itemsDeleted); }
/// <summary> /// Adds a checkbox with the given text to the checklist /// </summary> /// <param name="text">The text on the checkbox</param> private void AddItem(object text) { string itemText = text.ToString(); // Error validatation. If the default to-do is there still, remove it. If it's empty, return if (string.IsNullOrWhiteSpace(text.ToString())) { return; } else if (CheckListItems.Count == 1 && CheckListList.ElementAt(0).Content.ToString() == DefaultTODO) { CheckListList.RemoveAt(0); } // Make a checkbox for the item and add it. CheckListList.Add(MakeCheckBoxForItem(itemText)); AddTextBox.Clear(); // Save the newly created item. DataDealer.WriteChecklistData(CheckListItems); // Fire the event. ItemAdded?.Invoke(this, itemText); }