1
votes

In my Control I have a ListBox. Each ListBoxItem is displayed (via ItemTemplate) as a Combobox whose ItemsSource is an ObservableCollection in the ViewModel of my Control.

Next to that ComboBox is a Button to delete an element from the list (the Button's Click Command is bound to a Delete-Command in the ViewModel of my control). This works fine as desired.

Now I want to be able to add new elements to the ListBox. I'd know how to do this by clicking a Button either somewhere outside the ListBox or in the ListBox's ItemTemplate, but instead I would like to add some kind of additional "empty" item as the last item of my ListBox.

This "empty" item should look like any other item, with the exception that the ComboBox has no selection. As soon as the user makes a selection, a new "empty" item has to be displayed. I hope you know what I mean...acutally it's a bit like the "Tags" editor when you post a new question here ;)

Any ideas??? (without breaking MVVM rules)...

1
If i understand right it seems that you need to add a property to your model - isEmpty. This property should be bound to the ComboBox.Visible propertyNoam M

1 Answers

1
votes

Instead of a ListBox, use a DataGrid with CanUserAddRows="True". It will add that "new line" row, and behave exactly as you want.