How to make simple combobox with selected value in XAML? How to make simple combobox with selected value in XAML? wpf wpf

How to make simple combobox with selected value in XAML?


I think this should work. Have a try.

<StackPanel>    <ComboBox>        <ComboBoxItem Tag="CO">Colorado</ComboBoxItem>        <ComboBoxItem Tag="CA" IsSelected="True">California</ComboBoxItem>        <ComboBoxItem Tag="NM">New Mexico</ComboBoxItem>    </ComboBox></StackPanel>


<ComboBox SelectedValuePath="Content" SelectedValue="{Binding Source="...", Path="..."}">   <ComboBoxItem Content="..." isSelected="true"/>   <ComboBoxItem Content="..." />   <ComboBoxItem Content="..." /></ComboBox>

It should work with content, tag... or any other property you'd like to bind.


<StackPanel>    <ComboBox AllowDrop="True">        <ComboBoxItem Tag="CO">Colorado</ComboBoxItem>        <ComboBoxItem Tag="CA" IsSelected="True">California</ComboBoxItem>        <ComboBoxItem Tag="NM">New Mexico</ComboBoxItem>    </ComboBox></StackPanel>

You need to set AllowDrop="True" for the combobox and isselected for the item.