ListBoxItem.Selected Event

Definition

Occurs when a ListBoxItem is selected.

public event System.Windows.RoutedEventHandler Selected;

Event Type

Examples

The following example shows how to subscribe to and handle this event.

<ListBoxItem Name="lbi0" Selected="OnSelected" Unselected="OnUnselected">Item 0</ListBoxItem>
private void OnSelected(object sender, RoutedEventArgs e)
{
    ListBoxItem lbi = e.Source as ListBoxItem;

    if (lbi != null)
    {
        label1.Content = lbi.Content.ToString() + " is selected.";
    }
}

Remarks

To know when the selection in a ListBox changes, listen for the SelectionChanged event.

Routed Event Information

Identifier field SelectedEvent
Routing strategy Bubbling
Delegate RoutedEventHandler

Applies to

Produk Versi
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9