A newer version of this page is available. Switch to the current version.


  • 5 minutes to read

The EnumItemsSourceBehavior class allows you to bind an enumeration to the ItemsSource property of any control.

Getting Started with EnumItemsSourceBehavior

Assume that you need to represent the following UserRole enumeration in the ComboBoxEdit control.

public enum UserRole {
    [Image("pack://application:,,,/Images/Admin.png"), Display(Name = "Admin", Description = "High level of access", Order = 1)]
    [Image("pack://application:,,,/Images/Moderator.png"), Display(Name = "Moderator", Description = "Average level of access", Order = 2)]
    [Image("pack://application:,,,/Images/User.png"), Display(Name = "User", Description = "Low level of access", Order = 3)]

There are several attributes defined for each enum member.

  • Image is the DataAnnotation attribute that allows assigning an image to a corresponding member of the enumeration. Use the AllowImages property to control image visibility.
  • Display is a standard Display attribute that provides a general-purpose attribute that allows you to specify localizable strings for types and members of entity partial classes.

To assign the UserRole enumeration to the LookUpEditBase.ItemsSource property of the ComboBoxEdit control, define the EnumItemsSourceBehavior as follows.

        <dxmvvm:EnumItemsSourceBehavior EnumType="{x:Type common:UserRole}"/>

As a result, the combo box will be automatically bound to the enum values.


If you wish, you can further customize the editor’s ItemTemplate, for instance:

<dxe:ComboBoxEdit Name="comboBoxEdit" IsTextEditable="False" ApplyItemTemplateToSelectedItem="True">
        <dxmvvm:EnumItemsSourceBehavior EnumType="{x:Type common:UserRole}" SortMode="DisplayName" ImageSize="8,8"/>
                <TextBlock Text="{Binding Name}"/>
                <TextBlock Text="{Binding Description}" Grid.Row="1" FontSize="9"/>


Define EnumItemsSourceBehavior from the Visual Studio Designer

SmartTag allows you to use the EnumItemsSourceBehavior from the Visual Studio designer. Below are step-by-step instructions that describe how to do this for the ComboBoxEdit control.

Open the ComboBoxEdit smart tag panel using the SmartTagButton button at the top-right corner of the selected control.


Switch to the MVVM tab and add the EnumItemsSourceBehavior by clicking a corresponding item in the Add Behavior drop down menu. Then, specify the EnumItemsSourceBehavior’s properties as shown in the screenshot below.


Build and run the application to see the changes to the combo-box items at runtime.



View Example

Imports System.Collections.ObjectModel
Imports DevExpress.Mvvm.POCO
Imports EnumItemsSourceBehaviorExample.Common

Namespace EnumItemsSourceBehaviorExample.ViewModel
    Public Class MainViewModel
        Protected Sub New()
            Users = New ObservableCollection(Of User)() From {User.Create(0, "Jack", UserRole.Administrator), User.Create(1, "Ron", UserRole.User), User.Create(2, "John", UserRole.User), User.Create(3, "Antoni", UserRole.User), User.Create(4, "Paul", UserRole.Moderator)}
            SelectedRole = UserRole.User
        End Sub
        Public Shared Function Create() As MainViewModel
            Return ViewModelSource.Create(Function() New MainViewModel())
        End Function

        Public Overridable Property Users() As ObservableCollection(Of User)
        Public Overridable Property SelectedRole() As UserRole
    End Class
End Namespace