SelectionChangedEventArgs Klasa

Definicja

Udostępnia dane dla zdarzenia SelectionChanged.

public ref class SelectionChangedEventArgs : System::Windows::RoutedEventArgs
public class SelectionChangedEventArgs : System.Windows.RoutedEventArgs
type SelectionChangedEventArgs = class
    inherit RoutedEventArgs
Public Class SelectionChangedEventArgs
Inherits RoutedEventArgs
Dziedziczenie
SelectionChangedEventArgs

Przykłady

Poniższy przykład tworzy zdarzenie ListBox i subskrybuje je SelectionChanged . Używa elementu SelectionChangedEventArgs , aby znaleźć wybrany element w elemencie 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;
}
Private Sub myListBox_SelectionChanged(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)

    Dim converter As BrushConverter = New BrushConverter()
    Dim color As String

    ' Show Rectangles that are the selected colors.
    For Each color In args.AddedItems

        If GetRectangle(color) Is Nothing Then
            Dim aRect As Rectangle = New Rectangle()
            aRect.Fill = CType(converter.ConvertFrom(color), Brush)
            aRect.Tag = color
            rectanglesPanel.Children.Add(aRect)
        End If

    Next

    ' Remove the Rectangles that are the unselected colors.
    For Each color In args.RemovedItems

        Dim removedItem As FrameworkElement = GetRectangle(color)
        If Not removedItem Is Nothing Then
            rectanglesPanel.Children.Remove(removedItem)
        End If

    Next

End Sub

Private Function GetRectangle(ByVal color As String) As FrameworkElement
    Dim rect As FrameworkElement
    For Each rect In rectanglesPanel.Children
        If rect.Tag.ToString() = color Then
            Return rect
        End If
    Next

    Return Nothing
End Function

Konstruktory

SelectionChangedEventArgs(RoutedEvent, IList, IList)

Inicjuje nowe wystąpienie klasy SelectionChangedEventArgs.

Właściwości

AddedItems

Pobiera listę zawierającą wybrane elementy.

Handled

Pobiera lub ustawia wartość wskazującą obecny stan obsługi zdarzeń dla zdarzenia kierowanego podczas podróży trasy.

(Odziedziczone po RoutedEventArgs)
OriginalSource

Pobiera oryginalne źródło raportowania określone przez testowanie trafień, przed ewentualnym Source dostosowaniem przez klasę nadrzędną.

(Odziedziczone po RoutedEventArgs)
RemovedItems

Pobiera listę zawierającą niezaznaczone elementy.

RoutedEvent

Pobiera lub ustawia skojarzone z tym RoutedEventArgs wystąpieniemRoutedEvent.

(Odziedziczone po RoutedEventArgs)
Source

Pobiera lub ustawia odwołanie do obiektu, który wzbudził zdarzenie.

(Odziedziczone po RoutedEventArgs)

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
InvokeEventHandler(Delegate, Object)

Wykonuje odpowiednie rzutowanie typu w celu wywołania delegata bezpiecznego SelectionChangedEventHandler typu dla SelectionChanged zdarzenia.

MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
OnSetSource(Object)

Po zastąpieniu w klasie pochodnej zapewnia punkt wejścia wywołania zwrotnego powiadomień za każdym razem, gdy wartość Source właściwości wystąpienia ulegnie zmianie.

(Odziedziczone po RoutedEventArgs)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też