Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
A ListBox control displays a collection of items that users can select from. The ListBox supports single or multiple selections and provides keyboard navigation, scrolling capabilities, and data binding functionality. It's commonly used in forms and applications where users need to choose from predefined options.
| Title | Description |
|---|---|
| Bind a ListBox to Data | Shows how to bind a ListBox to a data source. |
| Get a ListBoxItem | Shows how to retrieve a specific ListBoxItem from a ListBox. |
| Improve the Scrolling Performance of a ListBox | Shows how to optimize scrolling performance in a ListBox with many items. |
Styles and templates
You can modify the default ControlTemplate to give the ListBox control a unique appearance. For more information, see What are styles and templates? and How to create a template for a control.
When you create a ControlTemplate for a ListBox, your template might contain an ItemsPresenter within a ScrollViewer. The ItemsPresenter displays each item in the ListBox, and the ScrollViewer enables scrolling within the control. If the ItemsPresenter isn't the direct child of the ScrollViewer, you must give the ItemsPresenter the name ItemsPresenter.
Content property
The ListBox control uses the Items property as its content property. This property represents the collection of items displayed in the ListBox and supports data binding to various data sources.
Parts
The ListBox control doesn't define any named template parts.
Visual states
The following table lists the visual states for the ListBox control.
| VisualState Name | VisualStateGroup Name | Description |
|---|---|---|
| InvalidFocused | ValidationStates | The control has a validation error and has keyboard focus. |
| InvalidUnfocused | ValidationStates | The control has a validation error but doesn't have keyboard focus. |
| Valid | ValidationStates | The control is valid and has no validation errors. |
See also
.NET Desktop feedback