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 an instance of the class.

public EnumListBox()

Properties

EnumSortComparer

The IComparer<T> used to sort the enumeration values, or null to use default sorting.

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

Property Value

IComparer<Enum>:

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

The enumeration type.

public Type? EnumType { get; set; }

Property Value

Type

EnumValue

The current enumeration value.

public object? EnumValue { get; set; }

Property Value

object

IsFlagsEnum

Indicates whether the EnumType has the FlagsAttribute.

public bool IsFlagsEnum { get; }

Property Value

bool:

true if the EnumType has the FlagsAttribute; otherwise false.

IsNullAllowed

Indicates whether a null value entry is included in the list.

public bool IsNullAllowed { get; set; }

Property Value

bool:

true if a null value entry is included in the list; otherwise false. The default value is false.

IsOnPopup

Indicates 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.

NullValueText

The text to display for a null value item when IsNullAllowed is true.

public string NullValueText { get; set; }

Property Value

string

UseDisplayAttributes

Indicates 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 a specified item.

protected override DependencyObject GetContainerForItemOverride()

Returns

DependencyObject:

The element used to display a specified item.

IsItemItsOwnContainerOverride(object)

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

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

Specified item.

Returns

bool:

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

OnGotKeyboardFocus(KeyboardFocusChangedEventArgs)

Invoked when an unhandled System.Windows.Input.Keyboard.GotKeyboardFocus attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.

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

The KeyboardFocusChangedEventArgs that contains the event data.

OnKeyDown(KeyEventArgs)

Responds to the KeyDown event.

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

Provides data for KeyEventArgs.

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

Element used to display the specified item.

item object

Specified item.

Fields

EnumSortComparerProperty

Defines the EnumSortComparer property.

public static readonly DependencyProperty EnumSortComparerProperty

EnumTypeProperty

Defines the EnumType property.

public static readonly DependencyProperty EnumTypeProperty

EnumValueProperty

Defines the EnumValue property.

public static readonly DependencyProperty EnumValueProperty

IsFlagsEnumProperty

Defines the IsFlagsEnum property.

public static readonly DependencyProperty IsFlagsEnumProperty

IsNullAllowedProperty

Defines the IsNullAllowed property.

public static readonly DependencyProperty IsNullAllowedProperty

IsOnPopupProperty

Defines the IsOnPopup property.

public static readonly DependencyProperty IsOnPopupProperty

NullValuePlaceholderItem

An instance of a special placeholder item used to represent null values.

public static readonly object NullValuePlaceholderItem

NullValueTextProperty

Defines the NullValueText property.

public static readonly DependencyProperty NullValueTextProperty

UseDisplayAttributesProperty

Defines the UseDisplayAttributes property.

public static readonly DependencyProperty UseDisplayAttributesProperty

Extension Methods