How to: Bind a ListBox to Data

An application developer can create ListBox controls without specifying the contents of each ListBoxItem separately. You can use data binding to bind data to the individual items.

The following example shows how to create a ListBox that populates the ListBoxItem elements by data binding to a data source called Colors. In this case it is not necessary to use ListBoxItem tags to specify the content of each item.


  <src:myColors x:Key="Colors"/>
<ListBox Name="myListBox" HorizontalAlignment="Left" SelectionMode="Extended" 
      Width="265" Height="55" Background="HoneyDew" SelectionChanged="myListBox_SelectionChanged"
      ItemsSource="{Binding Source={StaticResource Colors}}" IsSynchronizedWithCurrentItem="true">

See Also