Auf Englisch lesen

Teilen über


Selector.SelectionChanged Ereignis

Definition

Tritt auf, wenn die Auswahl eines Selector geändert wird.

C#
public event System.Windows.Controls.SelectionChangedEventHandler SelectionChanged;

Ereignistyp

Beispiele

Im folgenden Beispiel wird gezeigt, wie das SelectionChanged Ereignis an ein Listenfeldsteuerelement angefügt wird.

XAML
<TextBox Name="tb" Width="140" Height="30"></TextBox>
<ListBox Name="lb" Width="100" Height="55" SelectionChanged="PrintText" SelectionMode="Single">
  <ListBoxItem>Item 1</ListBoxItem>
  <ListBoxItem>Item 2</ListBoxItem>
  <ListBoxItem>Item 3</ListBoxItem>
  <ListBoxItem>Item 4</ListBoxItem>
  <ListBoxItem>Item 5</ListBoxItem>
  <ListBoxItem>Item 6</ListBoxItem>
  <ListBoxItem>Item 7</ListBoxItem>
  <ListBoxItem>Item 8</ListBoxItem>
  <ListBoxItem>Item 9</ListBoxItem>
  <ListBoxItem>Item 10</ListBoxItem>
</ListBox>

Im folgenden Beispiel wird gezeigt, wie das SelectionChanged Ereignis behandelt wird.

C#
void PrintText(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
    tb.Text = "   You selected " + lbi.Content.ToString() + ".";
}

Hinweise

Dieses Ereignis tritt immer dann auf, wenn eine Auswahl geändert wird. Eine Auswahl kann nicht nur durch Benutzerinteraktionen, sondern auch durch Bindung sowie durch andere festgelegte Werte geändert werden.

Informationen zum Routingereignis

Bezeichnerfeld SelectionChangedEvent
Routingstrategie Bubbling
Delegat SelectionChangedEventHandler

Gilt für:

Produkt Versionen
.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