Skip to main content
.NET Framework Class Library
SelectorSelectionChanged Event

Occurs when the selection of a Selector changes.

Namespace:   System.Windows.Controls.Primitives
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax
Public Event SelectionChanged As [%$TOPIC/ms521574_en-us_VS_110_2_0_0_0_0%]
public event [%$TOPIC/ms521574_en-us_VS_110_2_0_1_0_0%] SelectionChanged
public:
 event [%$TOPIC/ms521574_en-us_VS_110_2_0_2_0_0%]^ SelectionChanged {
	void add ([%$TOPIC/ms521574_en-us_VS_110_2_0_2_0_1%]^ value);
	void remove ([%$TOPIC/ms521574_en-us_VS_110_2_0_2_0_2%]^ value);
}
member SelectionChanged : IEvent<[%$TOPIC/ms521574_en-us_VS_110_2_0_3_0_0%],
    [%$TOPIC/ms521574_en-us_VS_110_2_0_3_0_1%]>
JScript does not support events.
<object SelectionChanged="[%$TOPIC/ms521574_en-us_VS_110_2_0_5_0_0%]" .../>
Routed Event Information

Identifier field

SelectionChangedEvent

Routing strategy

Bubbling

Delegate

SelectionChangedEventHandler

Remarks

This event occurs whenever there is a change to a selection. A selection can be changed not only by user interaction but also by binding as well as other set values.

Examples

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>

The following example shows how to handle the SelectionChanged event.

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
void PrintText(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
    tb.Text = "   You selected " + lbi.Content.ToString() + ".";
}
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1