blog

Home / DeveloperSection / Blogs / WPF ComboBox

WPF ComboBox

Uttam Misra 9372 05-May-2011

ComboBox element represents a ComboBox control in XAML.  

<ComboBox></ComboBox> 

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"
            Margin="8,14,0,0">           
</ComboBox>

 

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>
</ComboBox>

 


wpf wpf 
Updated 18-Sep-2014
More than 18 years of working experience in IT sector. We are here to serve you best.

Leave Comment

Comments

Liked By