0

I'm trying to add a "fake" item to my source list binded to a combobox.

<Window ...
        DataContext="{Binding Source={x:Static local:Singleton.Instance}}">
    ...
        <ComboBox ItemsSource="{Binding MyList}">

--

public List<Object> MyList{ get; private set; }

I want to have a "Add New" as a combobox item that do not belong to MyList, since I need to have only proper objects inside it. If I try to add it programmatically an exception is raised since the source cannot be edit in such a way.

  • 1
    Possible duplicate of [How to display default text "--Select Team --" in combo box on pageload in WPF?](https://stackoverflow.com/questions/1426050/how-to-display-default-text-select-team-in-combo-box-on-pageload-in-wpf) – CynicalSection Mar 14 '18 at 18:34

1 Answers1

0

Add the following to your XAML

IsEditable="True"
Text="Add New"

Caution: If the user selects one of the bound values, they cannot "go back" and select "Add New" as it will no longer appear. Also, now that the control is editable, you will need to validate the content before you do any processing to avoid potential errors introduced by the user entering a bad value.

Pierce
  • 143
  • 10