SelectionChangedEventArgs SelectionChangedEventArgs SelectionChangedEventArgs SelectionChangedEventArgs Class

定義

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
継承
SelectionChangedEventArgsSelectionChangedEventArgsSelectionChangedEventArgsSelectionChangedEventArgs

次の例では、ListBoxを作成し、SelectionChangedイベントをサブスクライブします。The following example creates a ListBox and subscribes to the SelectionChanged event. では、 SelectionChangedEventArgsを使用して、 ListBoxで選択した項目を検索します。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

コンストラクター

SelectionChangedEventArgs(RoutedEvent, IList, IList) SelectionChangedEventArgs(RoutedEvent, IList, IList) SelectionChangedEventArgs(RoutedEvent, IList, IList) SelectionChangedEventArgs(RoutedEvent, IList, IList)

SelectionChangedEventArgs クラスの新しいインスタンスを初期化します。Initializes a new instance of the SelectionChangedEventArgs class.

プロパティ

AddedItems AddedItems AddedItems AddedItems

選択された項目の一覧を取得します。Gets a list that contains the items that were selected.

Handled Handled Handled Handled

ルーティング イベントがルートをたどる際のイベント処理の現在の状態を示す値を取得または設定します。Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.

(Inherited from RoutedEventArgs)
OriginalSource OriginalSource OriginalSource OriginalSource

親クラスによって Source が調整される前の、純粋なヒット テストで判断される元の報告ソースを取得します。Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.

(Inherited from RoutedEventArgs)
RemovedItems RemovedItems RemovedItems RemovedItems

選択されなかった項目の一覧を取得します。Gets a list that contains the items that were unselected.

RoutedEvent RoutedEvent RoutedEvent RoutedEvent

この RoutedEventArgs インスタンスに関連付けられている RoutedEvent を取得または設定します。Gets or sets the RoutedEvent associated with this RoutedEventArgs instance.

(Inherited from RoutedEventArgs)
Source Source Source Source

イベントを発生させたオブジェクトへの参照を取得または設定します。Gets or sets a reference to the object that raised the event.

(Inherited from RoutedEventArgs)

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object)

適切な型のキャストを実行して、SelectionChangedEventHandler イベントのタイプ セーフな SelectionChanged デリゲートを呼び出します。Performs the proper type casting to call the type-safe SelectionChangedEventHandler delegate for the SelectionChanged event.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
OnSetSource(Object) OnSetSource(Object) OnSetSource(Object) OnSetSource(Object)

派生クラスでオーバーライドした場合、インスタンスの Source プロパティの値が変更されるたびに、通知コールバックのエントリ ポイントを提供します。When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes.

(Inherited from RoutedEventArgs)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象

こちらもご覧ください