Search code examples
c#xamlcomboboxworkflow-foundation

WPF ComboBox - is it possible to insert your own text?


I have a ComboBox that contains values and you can search for a value by using the IsTextSearchEnabled property on the ComboBox. This works as expected.

However, in case the value isn't inside the combobox, I want the user to insert their own value, but instead of creating a textbox, I wonder if the user can just insert the value into the combobox?

At the moment when I do input a value, the combobox goes red to indicate that the value they typed cannot be found (I assume)

using this XAML

ItemsSource="{Binding TheValues, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding TheValue}"

The Itemsource is a list that are guids.. here is the property of the itemsource

public List<Guid> TheValues
{
   get
   {
      return m_TheValues;
   }
   set
   {
     m_TheValues= value;
   }
}

Any help (even to say it cannot be done) would be good.

Thanks.


Solution

  • GUID constructors can accept a string as a parameter try something like this

    public void AddValue(string newGuid)
            {
                Guid g  =  new Guid(newGuid);
                m_TheValues.Add(g); 
            }