In this post, I will demonstrate how to Populating WPF ComboBox with data and display selected value in the label from ComboBox. Let’s start.
Step 1: Open Visual Studio 2010. On the File Menu, Click New -> Project. This opens the New Project dialog. In New Project, under Installed Templates, expand the Visual C#/Visual Basic node, click WPF Application. In Name box, type “WPFDropDown” and click OK button to continue.

Step 2: In the WPFDropDown Project, open the MainPage.Xaml. You will see following code given below.
<Grid>
<ComboBox Height="23" SelectionChanged="comboBox1_SelectionChanged" HorizontalAlignment="Left" Margin="95,38,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" />
<Label Height="28" HorizontalAlignment="Left" Margin="230,34,0,0" Name="label1" VerticalAlignment="Top" Foreground="#FFD11818" FontSize="14" FontFamily="Verdana" />
<Label FontFamily="Verdana" Content="Select:" FontSize="14" Foreground="#FFD11818" Height="28" HorizontalAlignment="Left" Margin="32,37,0,0" Name="label2" VerticalAlignment="Top" Width="57" />
</Grid>

The XAML code snippet shown below provides background gradient effect .
<Window.Background>
<LinearGradientBrush EndPoint="0,1.5" StartPoint="0,0.5">
<GradientStop Color="AliceBlue" Offset="0.5"/>
<GradientStop Color="LightSkyBlue" Offset="0.07"/>
</LinearGradientBrush>
</Window.Background>
Step 3: In the WPFDropDown Project, open the MainPage.Xaml.cs/MainPage.Xaml.vb and write following code inside the MainWindow Class as shown below:
C#
public MainWindow()
{
InitializeComponent();
comboBox1.ItemsSource = fetchList();
comboBox1.DisplayMemberPath = "Item";
comboBox1.SelectedValuePath = "value";
}
public List<DropDownList> fetchList()
{
List<DropDownList> objDDL = new List<DropDownList>();
objDDL.Add(new DropDownList() { Item = "APPLE", value = "1" });
objDDL.Add(new DropDownList() { Item = "ORANGE", value = "2" });
objDDL.Add(new DropDownList() { Item = "MANGO", value = "3" });
return objDDL;
}
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var lab = "Selected value " + comboBox1.SelectedValue;
label1.Content = lab;
}
}
public class DropDownList
{
public String Item { get; set; }
public String value { get; set; }
}
VB.NET
Public Sub New()
InitializeComponent()
comboBox1.ItemsSource = fetchList()
comboBox1.DisplayMemberPath = "Item"
comboBox1.SelectedValuePath = "value"
End Sub
Public Function fetchList() As List(Of DropDownList)
Dim objDDL As New List(Of DropDownList)()
objDDL.Add(New DropDownList() With { _
.Item = "APPLE", _
.value = "1" _
})
objDDL.Add(New DropDownList() With { _
.Item = "ORANGE", _
.value = "2" _
})
objDDL.Add(New DropDownList() With { _
.Item = "MANGO", _
.value = "3" _
})
Return objDDL
End Function
Private Sub comboBox1_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
Dim lab = "Selected value " + comboBox1.SelectedValue
label1.Content = lab
End Sub
Public Class DropDownList
Public Property Item() As [String]
Get
Return m_Item
End Get
Set(ByVal value As [String])
m_Item = value
End Set
End Property
Private m_Item As [String]
Public Property value() As [String]
Get
Return m_value
End Get
Set(ByVal value As [String])
m_value = value
End Set
End Property
Private m_value As [String]
End Class
Here is a preview of the collection list that will be returned when you hit a breakpoint.

When you run the application and you will see populated combo box.

Download
WPFDropDownC#.zip (165.91 kb)
WpfDropdownListVb.zip (78.78 kb)