SelectionChangedEventArgs Constructor
.NET Framework 4.5
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Initializes a new instance of the SelectionChangedEventArgs class.
Namespace: System.Windows.Controls
Assembly: PresentationFramework (in PresentationFramework.dll)
Parameters
- id
- Type: System.Windows.RoutedEvent
The event identifier (ID).
- removedItems
- Type: System.Collections.IList
The items that were unselected during this event.
- addedItems
- Type: System.Collections.IList
The items that were selected during this event.
The following example creates a ListBox and subscribes to the SelectionChanged event. It uses the SelectionChangedEventArgs to find the selected item in the ListBox.
<WrapPanel Width="500" Orientation="Horizontal" Name="rectanglesPanel">
<WrapPanel.Resources>
<Style TargetType="Rectangle">
<Setter Property="Height" Value="20"/>
<Setter Property="Width" Value="20"/>
<Setter Property="Margin" Value="5"/>
</Style>
</WrapPanel.Resources>
</WrapPanel>
<ListBox Name="myListBox" HorizontalAlignment="Left" SelectionMode="Extended"
Width="265" Height="55" Background="HoneyDew" SelectionChanged="myListBox_SelectionChanged"
ItemsSource="{Binding Source={StaticResource Colors}}" IsSynchronizedWithCurrentItem="true">
</ListBox>
void myListBox_SelectionChanged(object sender, SelectionChangedEventArgs args) { BrushConverter converter = new BrushConverter(); // Show Rectangles that are the selected colors. foreach (string color in args.AddedItems) { if (GetRectangle(color) == null) { Rectangle aRect = new Rectangle(); aRect.Fill = (Brush) converter.ConvertFrom(color); aRect.Tag = color; rectanglesPanel.Children.Add(aRect); } } // Remove the Rectangles that are the unselected colors. foreach (string color in args.RemovedItems) { FrameworkElement removedItem = GetRectangle(color); if (removedItem != null) { rectanglesPanel.Children.Remove(removedItem); } } } FrameworkElement GetRectangle(string color) { foreach (FrameworkElement rect in rectanglesPanel.Children) { if (rect.Tag.ToString() == color) return rect; } return null; }
Windows 8 Consumer Preview, Windows Server 8 Beta, Windows 7, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.