示例#1
0
        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);
            }
        }
示例#2
0
 private void Rename(EditComboBoxItem item)
 {
     if (RenameAction != null)
     {
         RenameAction(item);
     }
 }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
            }
        }