Selector.SelectionChanged Selector.SelectionChanged Selector.SelectionChanged Selector.SelectionChanged Event

Definition

Tritt auf, wenn die Auswahl eines Selector geändert wird.Occurs when the selection of a Selector changes.

public:
 event System::Windows::Controls::SelectionChangedEventHandler ^ SelectionChanged;
public event System.Windows.Controls.SelectionChangedEventHandler SelectionChanged;
member this.SelectionChanged : System.Windows.Controls.SelectionChangedEventHandler 
Public Custom Event SelectionChanged As SelectionChangedEventHandler 

Beispiele

Das folgende Beispiel zeigt, wie Sie das Anfügen der SelectionChanged Ereignis, um ein Listenfeld-Steuerelement.The following example shows how to attach the SelectionChanged event to a list box control.

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

Das folgende Beispiel zeigt, wie Sie behandelt die SelectionChanged Ereignis.The following example shows how to handle the SelectionChanged event.

void PrintText(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
    tb.Text = "   You selected " + lbi.Content.ToString() + ".";
}
Private Sub PrintText(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)

    Dim lbsender As ListBox
    Dim li As ListBoxItem

    lbsender = CType(sender, ListBox)
    li = CType(lbsender.SelectedItem, ListBoxItem)
    tb.Text = "   You selected " & li.Content.ToString & "."
End Sub

Hinweise

Dieses Ereignis tritt auf, wenn eine Änderung an einer Auswahl vorhanden ist.This event occurs whenever there is a change to a selection. Eine Auswahl kann nicht nur durch Benutzerinteraktion, sondern auch durch die Bindung als auch für andere festgelegten Werte geändert werden.A selection can be changed not only by user interaction but also by binding as well as other set values.

Informationen zum RoutingereignisRouted Event Information

Feld "ID"Identifier field SelectionChangedEvent
Routing-StrategieRouting strategy BubblingBubbling
delegateDelegate SelectionChangedEventHandler

Gilt für: