Language

DragDrop.Drop 添付イベント

定義

ドロップ ターゲットとして機能する要素の境界内でオブジェクトがドロップされたときに発生します。

see AddDropHandler, and RemoveDropHandler
see AddDropHandler, and RemoveDropHandler
see AddDropHandler, and RemoveDropHandler

例

次の例は、Drop要素のEllipse イベント ハンドラーを示しています。 このコードは、ドラッグ アンド ドロップ操作の効果を適用します。 省略記号の上にドラッグする DataObject に、 Brushに変換できる文字列データが含まれているかどうかを確認します。 その場合、 Brush が楕円に適用されます。 データを Brushに変換できない場合、アクションは実行されません。

private void ellipse_Drop(object sender, DragEventArgs e)
{
    Ellipse ellipse = sender as Ellipse;
    if (ellipse != null)
    {
        // If the DataObject contains string data, extract it.
        if (e.Data.GetDataPresent(DataFormats.StringFormat))
        {
            string dataString = (string)e.Data.GetData(DataFormats.StringFormat);

            // If the string can be converted into a Brush, 
            // convert it and apply it to the ellipse.
            BrushConverter converter = new BrushConverter();
            if (converter.IsValid(dataString))
            {
                Brush newFill = (Brush)converter.ConvertFromString(dataString);
                ellipse.Fill = newFill;
            }
        }
    }
}
Private Sub Ellipse_Drop(ByVal sender As System.Object, ByVal e As System.Windows.DragEventArgs)
    Dim ellipse = TryCast(sender, Ellipse)
    If ellipse IsNot Nothing Then

        ' If the DataObject contains string data, extract it.
        If e.Data.GetDataPresent(DataFormats.StringFormat) Then
            Dim dataString = e.Data.GetData(DataFormats.StringFormat)

            ' If the string can be converted into a Brush, convert it.
            Dim converter As New BrushConverter()
            If converter.IsValid(dataString) Then
                Dim newFill As Brush = CType(converter.ConvertFromString(dataString), Brush)
                ellipse.Fill = newFill
            End If
        End If
    End If
End Sub

注釈

Drop イベントは、ドロップ ターゲットとして機能する要素の境界内でオブジェクトがドロップされたときに 1 回発生します。 要素の AllowDrop プロパティが false場合、このイベントは発生しません。 このイベントは、ドラッグ アンド ドロップ操作を終了します。

Drop イベント ハンドラーでは、DataObjectから転送されたデータを抽出し、アプリケーションで必要なデータの処理を実行します。 コピーや移動など、ドロップの効果をドラッグ ソースに通知するには、DragEventArgs.Effects イベント ハンドラーでDropプロパティを設定します。 このプロパティの値は、ドラッグ アンド ドロップ操作を開始した DoDragDrop メソッドの戻り値です。 返される値が、allowedEffectsの呼び出しで指定されたDoDragDropのいずれかに一致しない場合、ドラッグ アンド ドロップ操作は実行されません。 DragEventArgs.Effects プロパティの初期値は、allowedEffects メソッドの呼び出しで指定されたDoDragDropと同じです。 DragEventArgs.Effects プロパティを設定しない場合、この初期値が返され、allowedEffectsが発生したものと見なされます。

ルーティング イベント情報

品目 価値
識別子フィールド DropEvent
ルーティング戦略 バブル
代理人 DragEventHandler

対応するトンネリング イベントが PreviewDrop。

適用対象

こちらもご覧ください