private void AutoMergeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (SelectedItemsList != null) { foreach (var removedItem in e.RemovedItems.Cast <ChangesetViewModel>()) { SelectedItemsList.Remove(removedItem); } foreach (var addItem in e.AddedItems.Cast <ChangesetViewModel>()) { SelectedItemsList.Add(addItem); } } }
private void AddSelectedItem(object obj) { if (obj == null) { return; } if (string.IsNullOrWhiteSpace(obj.ToString())) { return; } if (Results.Contains(obj)) { Results.Remove(obj); } //resultStack.Visibility = Visibility.Collapsed; foreach (var item in AvailableItemsSource) { if (item.ToString() == obj.ToString()) { if (SelectedItemsList == null) { SelectedItemsList = new List <object>(); } if (SelectedItemsList.Contains(item)) { return; } SelectedItemsList.Add(item); } } var bt = new Button(); bt.Content = obj.ToString(); bt.Name = obj.ToString(); bt.DataContext = obj; var firstParagraph = textBox.GetFirstParagraph(); if (firstParagraph != null) { firstParagraph.Inlines.Add(bt); } List <Inline> runs = new List <Inline>(); foreach (var item in firstParagraph.Inlines) { if (item is Run) { runs.Add(item); } } foreach (var item in runs) { firstParagraph.Inlines.Remove(item); } textBox.Focus(); textBox.MoveCaretToEnd(); }