private void LoadLineCollection(ObservableCollection <string> items) { if (this.collectionChangedHooked == false) { items.CollectionChanged += Items_CollectionChanged; this.collectionChangedHooked = true; } this.LineCollection.Clear(); // input list of items is emtpy. add a blank line. if (items.Count == 0) { items.Add(""); } else { foreach (var item in items) { var line = new ItemsControlTextItem(item); this.LineCollection.Add(line); } } }
private void Items_CollectionChanged( object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { var ix = e.NewStartingIndex; foreach (var item in e.NewItems) { var line = new ItemsControlTextItem(item as string); this.LineCollection.Insert(ix, line); ix += 1; } } if (e.OldItems != null) { var ix = e.OldStartingIndex; foreach (var item in e.OldItems) { this.LineCollection.RemoveAt(ix); } } }