Version

Bind xamComboEditor to a Collection

You can bind xamComboEditor™ to several different data sources, including a collection that implements the IEnumerable interface. You can use an ObjectDataProvider to expose your collection to the presentation layer of your application. If you have not created an ObjectDataProvider yet, please read and follow the steps on Creating an ObjectDataProvider before proceeding with the rest of this topic.

The xamComboEditor control does not bind directly to a data source; instead, xamComboEditor uses an instance of a ComboBoxItemsProvider object to bind to data. You can data bind the ComboBoxItemsProvider object using the same patterns you would use for any Microsoft® Windows® Presentation Foundation ItemsControl. You can set the ItemsSource property to a binding expression that references a collection of objects to populate the drop-down list.

The default behavior of an ItemsControl is to display the results of the ToString method of the underlying object. You can override this default behavior either by creating a DataTemplate that determines the visual tree of each item or by setting the DisplayMemberPath and ValuePath properties that the ComboBoxItemsProvider object conveniently provide. You can set the DisplayMemberPath property to the name of a property on your business object that you want to display to the end user. You can set the ValuePath property to the name of a property on your business object that you want to store as the underlying value of xamComboEditor. The data type that xamComboEditor is editing must match the data type of the property that you specify as the ValueType property of the xamComboEditor. For example, if you set the ValuePath property of a ComboBoxItemsProvider object to a property that returns an integer, you should also set the ValueType property of xamComboEditor to an integer data type.

The following example code demonstrates how to bind xamComboEditor to an ObjectDataProvider.

In XAML:

...
<!--Notice that the ValueType property is set to the same data type as the property specified for the ValuePath property.
The sys: prefix is mapped to the XML namespace 'clr-namespace:System;assembly=mscorlib'-->
<igEditors:XamComboEditor ValueType="{x:Type sys:Double}" VerticalAlignment="Top">
<igEditors:XamComboEditor.ItemsProvider>
                <igEditors:ComboBoxItemsProvider ItemsSource="{Binding Source={StaticResource CarData}}"
DisplayMemberPath="Make" ValuePath="BasePrice" />
        </igEditors:XamComboEditor.ItemsProvider>
</igEditors:XamComboEditor>
...