private void Add() { var current = _items.FirstOrDefault(item => !item.IsUnselectable && item.IsCurrent); if (current != null) { current.IsCurrent = false; } var newItem = new EditComboBoxItem() { Title = String.Format("{0}{1}", newItemPrefix, _items.Count(item => item.Title.StartsWith(newItemPrefix)) + 1), IsUnselectable = false, IsCurrent = true, }; newItem.SelectAction = () => Select(newItem); newItem.PropertyChanged += (o, e) => { if (e.PropertyName == EditComboBoxItem.TitlePropertyName) { Rename(o as EditComboBoxItem); } }; _items.Add(newItem); if (AddAction != null) { AddAction(newItem); } }
private void Rename(EditComboBoxItem item) { if (RenameAction != null) { RenameAction(item); } }
private void Select(EditComboBoxItem item) { var currentItem = _items.FirstOrDefault(i => i.IsCurrent); if (currentItem != null) { currentItem.IsCurrent = false; } item.IsCurrent = true; if (SelectAction != null) { SelectAction(item); } }
private void Del() { var oldItem = _items.FirstOrDefault(item => !item.IsUndeletable && item.IsCurrent == true); EditComboBoxItem oldItemBackup = null; if (oldItem != null) { oldItemBackup = new EditComboBoxItem() { Title = oldItem.Title, LinkedObject = oldItem.LinkedObject } } ; _items.RemoveAll(item => !item.IsUndeletable && item.IsCurrent == true); if (DelAction != null) { DelAction(oldItemBackup); } }