Occurs when the selection of a
Selector changes.
Namespace: System.Windows.Controls.Primitives
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation

Syntax
Visual Basic (Declaration)
Public Event SelectionChanged As SelectionChangedEventHandler
Dim instance As Selector
Dim handler As SelectionChangedEventHandler
AddHandler instance.SelectionChanged, handler
public event SelectionChangedEventHandler SelectionChanged
public:
event SelectionChangedEventHandler^ SelectionChanged {
void add (SelectionChangedEventHandler^ value);
void remove (SelectionChangedEventHandler^ value);
}
/** @event */
public void add_SelectionChanged (SelectionChangedEventHandler value)
/** @event */
public void remove_SelectionChanged (SelectionChangedEventHandler value)
In JScript, you can handle the events defined by a class, but you cannot define your own.
<object SelectionChanged="SelectionChangedEventHandler" .../>

Routed Event Information

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.

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

Platforms
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information
.NET Framework
Supported in: 3.0

See Also