In This Article

EnumListBox Class

Represents a list box that automatically presents the values of an enumeration.

public class EnumListBox : ListBox
Inheritance:
object Visual UIElement FrameworkElement Control ItemsControl Selector ListBox object

Constructors

EnumListBox()

Initializes a new instance of the EnumListBox class.

public EnumListBox()

Properties

EnumSortComparer

Gets or sets the IComparer<T> used to sort the enumeration values.

public IComparer<Enum> EnumSortComparer { get; set; }

Property Value

IComparer<Enum>:

The IComparer<T> used to sort the enumeration values; otherwise null to use default sorting. By default, enumeration values are sorted by the order in which the values are defined. When UseDisplayAttributes is true, the DisplayAttribute.Order, if any, will be preferred over the definition order.

EnumType

Gets or sets the enumeration type.

public Type EnumType { get; set; }

Property Value

Type:

The enumeration type.

EnumValue

Gets or sets the current enumeration value.

public object EnumValue { get; set; }

Property Value

object:

The current enumeration value.

IsFlagsEnum

Gets a value indicating whether the EnumType has the FlagsAttribute.

public bool IsFlagsEnum { get; }

Property Value

bool:

true if the EnumType has the FlagsAttribute; otherwise false.

IsOnPopup

Gets or sets whether the control is being used on a popup, which affects how value changes are handled.

public bool IsOnPopup { get; set; }

Property Value

bool:

true if the control is being used on a popup; otherwise, false.

UseDisplayAttributes

Gets or sets a value indicating whether enumeration values should be displayed using an associated DisplayAttribute, if any.

public bool UseDisplayAttributes { get; set; }

Property Value

bool:

true if enumeration values should be displayed using an associated DisplayAttribute, if any; otherwise false. The default value is false.

Methods

GetContainerForItemOverride()

Creates or identifies the element used to display the specified item.

protected override DependencyObject GetContainerForItemOverride()

Returns

DependencyObject:

The element that is used to display the given item.

IsItemItsOwnContainerOverride(object)

Determines if the specified item is (or is eligible to be) its own item container.

protected override bool IsItemItsOwnContainerOverride(object item)
Parameter Type Description
item object

Specified item.

Returns

bool:

true if the item is its own item container; otherwise, false.

OnGotKeyboardFocus(KeyboardFocusChangedEventArgs)

Occurs when a control within this control's hierarchy gains keyboard focus.

protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
Parameter Type Description
e KeyboardFocusChangedEventArgs

The KeyboardFocusChangedEventArgs that contains data related to this event.

OnKeyDown(KeyEventArgs)

Occurs when a key is pressed.

protected override void OnKeyDown(KeyEventArgs e)
Parameter Type Description
e KeyEventArgs

The KeyEventArgs that contains the event data.

OnPropertyChanged(DependencyPropertyChangedEventArgs)

Invoked whenever the effective value of any dependency property on this FrameworkElement has been updated. The specific dependency property that changed is reported in the arguments parameter. Overrides System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs).

protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
Parameter Type Description
e DependencyPropertyChangedEventArgs

The event data that describes the property that changed, as well as old and new values.

PrepareContainerForItemOverride(DependencyObject, object)

Prepares the specified element to display the specified item.

protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
Parameter Type Description
element DependencyObject

The System.Windows.DependencyObject that is the wrapper element.

item object

The item that is being wrapped.

Fields

EnumSortComparerProperty

Identifies the EnumSortComparer dependency property. This field is read-only.

public static readonly DependencyProperty EnumSortComparerProperty

EnumTypeProperty

Identifies the EnumType dependency property. This field is read-only.

public static readonly DependencyProperty EnumTypeProperty

EnumValueProperty

Identifies the EnumValue dependency property. This field is read-only.

public static readonly DependencyProperty EnumValueProperty

IsFlagsEnumProperty

Identifies the IsFlagsEnum dependency property. This field is read-only.

public static readonly DependencyProperty IsFlagsEnumProperty

IsOnPopupProperty

Identifies the IsOnPopup dependency property. This field is read-only.

public static readonly DependencyProperty IsOnPopupProperty

UseDisplayAttributesProperty

Identifies the UseDisplayAttributes dependency property. This field is read-only.

public static readonly DependencyProperty UseDisplayAttributesProperty