Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Silverlight combobox without items source with a bound selected value

0.00/5 (No votes)
8 Sep 2011 2  
A simple combo box that will have predefined items but the selected value bound to a property from our View Model.

Sometimes we just need a simple combo box that will have predefined items but the selected value must be bound to a property from our View Model. The XAML below is a simple approach to resolve the task:


XML
<combobox>
    Width="220"
    SelectedValue="{Binding Path=Employee.Gender, Mode=TwoWay}"
    SelectedValuePath="Content">
 <combobox.items>
  <comboboxitem content=" " />
  <comboboxitem content="Male" />
  <comboboxitem content="Female" />
 </combobox.items>
</combobox>

The trick is to set the SelectedValuePath to the Content and bind the SelectedValue.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here