Distinct Values in WPF Combobox

后端 未结 3 1983
时光取名叫无心
时光取名叫无心 2020-12-21 07:33

I would like to get distinct values in my databound combo box

as an example the values it has are: blue, blue, yellow, red, orange

I would like it to just di

3条回答
  •  隐瞒了意图╮
    2020-12-21 07:51

    Let's say your you have a List values = blue, blue, yellow, red, orange

    you can do

    ComboBox.ItemsSource = values.Distinct();
    

    or if you are going for MVVM approach you can create a property and bind combo box itemssource with a property like

    public List values
    {
        get
        {
        return value.Distinct();
         }
    }
    

提交回复
热议问题