0

I have a combobox in which I want to use the items of an enumeration as items source. However, I can't use directly the enumeration as item source, so I use a obeservable collection in this way:

public class MyViewModel
{
    public MyViewModel()
    {
         MyItemsSoruce = new ObservableCollection<MyEnum>();
         foreach(MyEnum iterator Enum.GetValues(typeof(MyEnum)))
         {
               MyItemsSource.Add(iterator);
         }
    }
}

This works, but the problem is that I don't have a null or black item at first position, so I can deselect the items of the combobox.

I have tried to add a null item first and later populate the collection with the foreach, it works, but the problem is that the first item of the combobox it is very small, the height is almost 0, so it is very hard to select it.

How could add a null item in the collection and show with the same height than the rest of items?

Thanks.

Álvaro García
  • 18,114
  • 30
  • 102
  • 193
  • Would it make sense to have a "None" item in the Enum? – Fildor Nov 22 '22 at 15:59
  • In the enumeration it has no sense, but in the UI it has. But If I could use the items of the enum I could simplify my code because I could avoid to use events to convert from the UI to the enum or try another conversion solutions. – Álvaro García Nov 22 '22 at 16:02

0 Answers0