Skip to main content

EnumItemsSourceBehavior Class

Binds a control’s ItemsSource property to an enumeration.

Namespace: DevExpress.Mvvm.UI

Assembly: DevExpress.Xpf.Core.v24.1.dll

NuGet Package: DevExpress.Wpf.Core

Declaration

[TargetType(typeof(ListBoxEdit))]
[TargetType(typeof(ItemsControl))]
[TargetType(typeof(LookUpEditBase))]
public class EnumItemsSourceBehavior :
    Behavior<FrameworkElement>

Remarks

You can use any of the following attributes with enumeration members:

The following code sample assigns the UserRole enumeration to the ComboBoxEdit.ItemsSource property:

EnumItemsSourceBehavior

<UserControl ...
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">
    <Grid>
        <dxe:ComboBoxEdit>
            <dxmvvm:Interaction.Behaviors>
                <dxmvvm:EnumItemsSourceBehavior EnumType="{x:Type common:UserRole}"/>
            </dxmvvm:Interaction.Behaviors>
        </dxe:ComboBoxEdit>
    </Grid>
</UserControl>
public enum UserRole {
    [Image("pack://application:,,,/Images/Admin.png"), Display(Name = "Admin", Description = "High level of access", Order = 1)]
    Administrator,
    [Image("pack://application:,,,/Images/Moderator.png"), Display(Name = "Moderator", Description = "Average level of access", Order = 2)]
    Moderator,
    [Image("pack://application:,,,/Images/User.png"), Display(Name = "User", Description = "Low level of access", Order = 3)]
    User
}

Customize Items

The EnumItemsSourceBehavior generates an array of EnumMemberInfo objects based on the specified enumeration and its attributes. This array is assigned to the control’s ItemsSource property.

The following example demonstrates how to use the ComboBoxEdit.ItemTemplate property to customize generated items:

Item Template with EnumItemsSourceBehavior

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

View Example: Bind a Control to an Enumeration

The following code snippets (auto-collected from DevExpress Examples) contain references to the EnumItemsSourceBehavior class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

Inheritance

Object
DispatcherObject
DependencyObject
Freezable
Animatable
DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
DevExpress.Mvvm.UI.Interactivity.Behavior
DevExpress.Mvvm.UI.Interactivity.Behavior<FrameworkElement>
EnumItemsSourceBehavior
See Also