SelectionChangedEventArgs Class
.NET Framework 3.0
Provides data for the SelectionChanged event.
Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
This example shows how to create a ListBox using the Extensible Application Markup Language (XAML) and implement event handlers in C# or Microsoft Visual Basic to handle selection changes.
The ListBox in the following XAML example contains multiple list items. When the user selects one of the items, the event handler displays the name of the selected item in the TextBox.
<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>
void PrintText(object sender, SelectionChangedEventArgs args) { ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem); tb.Text = " You selected " + lbi.Content.ToString() + "."; }
For the complete sample see: List Box Sample.
System.Object
System.EventArgs
System.Windows.RoutedEventArgs
System.Windows.Controls.SelectionChangedEventArgs
System.EventArgs
System.Windows.RoutedEventArgs
System.Windows.Controls.SelectionChangedEventArgs
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.Community Additions
ADD
Show: