SelectionChangedEventArgs Classe

Definição

Fornece dados para o evento de SelectionChanged .Provides data for the SelectionChanged event.

public ref class SelectionChangedEventArgs : System::Windows::RoutedEventArgs
public class SelectionChangedEventArgs : System.Windows.RoutedEventArgs
type SelectionChangedEventArgs = class
    inherit RoutedEventArgs
Public Class SelectionChangedEventArgs
Inherits RoutedEventArgs
Herança
SelectionChangedEventArgs

Exemplos

O exemplo a seguir cria ListBox um e assina o SelectionChanged evento.The following example creates a ListBox and subscribes to the SelectionChanged event. Ele usa o SelectionChangedEventArgs para localizar o item selecionado ListBoxno.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;
}
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

Construtores

SelectionChangedEventArgs(RoutedEvent, IList, IList)

Inicializa uma nova instância da classe SelectionChangedEventArgs.Initializes a new instance of the SelectionChangedEventArgs class.

Propriedades

AddedItems

Obtém uma lista que contém os itens que foram selecionados.Gets a list that contains the items that were selected.

Handled

Obtém ou define um valor que indica o estado atual de manipulação de eventos para um evento roteado enquanto ele trafega na rota.Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.

(Herdado de RoutedEventArgs)
OriginalSource

Obtém a origem de relatório original conforme determinada pelo teste de clique puro, antes de qualquer ajuste possível da Source por parte de uma classe pai.Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.

(Herdado de RoutedEventArgs)
RemovedItems

Obtém uma lista que contém os itens que foram desmarcados.Gets a list that contains the items that were unselected.

RoutedEvent

Obtém ou define o RoutedEvent associado a esta instância do RoutedEventArgs.Gets or sets the RoutedEvent associated with this RoutedEventArgs instance.

(Herdado de RoutedEventArgs)
Source

Obtém ou define uma referência ao objeto que ativou o evento.Gets or sets a reference to the object that raised the event.

(Herdado de RoutedEventArgs)

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
InvokeEventHandler(Delegate, Object)

Executa a conversão de tipo adequada para chamar o representante SelectionChangedEventHandler fortemente tipado para o evento SelectionChanged.Performs the proper type casting to call the type-safe SelectionChangedEventHandler delegate for the SelectionChanged event.

MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
OnSetSource(Object)

Quando substituído em uma classe derivada, fornece um ponto de entrada de retorno de chamada de notificação sempre que o valor da propriedade Source de uma instância muda.When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes.

(Herdado de RoutedEventArgs)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Aplica-se a

Veja também