WPF ComboBox

ComboBox element represents a ComboBox control in XAML.  


1.      Width and Height properties represent width and height of a ComboBox.

2.      X:Name property represents the name of the control.

3.      Margin property sets the location of a ComboBox on the parent control (Location on Form or any other parent control).

4.      HorizontalAlignment and VerticalAlignment properties are used to set horizontal and vertical alignments.

5.      The IsSelected property of the ComboBox control sets an item as currently selected item in the ComboBox. 

<ComboBox Name='ComboBox1' Width='250' Height='35'
          VerticalAlignment='Top' HorizontalAlignment='Right'


The following line of code sets the IsSelected property of a ComboBox.

<ComboBoxItem Content='California' IsSelected='True' /> 

How to add items in ComboBox

ComboBox control hosts a collection of ComboBoxItem. The following sample code adds items to a ComboBox control at design-time using XAML.

<ComboBox Margin='8,14,0,0' Name='ComboBox1' HorizontalAlignment='Right'
         VerticalAlignment='Top' Width='230' Height='35'>
     <ComboBoxItem Content='California'></ComboBoxItem>
    <ComboBoxItem Content='NY'></ComboBoxItem>
    <ComboBoxItem Content='LA'></ComboBoxItem>
    <ComboBoxItem Content='Texas'></ComboBoxItem>
    <ComboBoxItem Content='Las Vegas'></ComboBoxItem>
    <ComboBoxItem Content='Florida'></ComboBoxItem>


Last updated:9/18/2014 1:23:55 PM
Uttam Misra

Uttam Misra

More than 18 years of working experience in IT sector. We are here to serve you best.


Leave Comment