DragDrop.DragEnter 연결된 이벤트

정의

이 이벤트는 개체를 놓기 대상의 역할을 하는 요소 경계 안으로 끄는 동안 발생합니다.

see AddDragEnterHandler, and RemoveDragEnterHandler
see AddDragEnterHandler, and RemoveDragEnterHandler
see AddDragEnterHandler, and RemoveDragEnterHandler

예제

다음 예제에서는 Ellipse 요소에 대한 DragEnter 이벤트 처리기를 보여 줍니다. 이 코드는 현재 Fill 브러시를 저장하여 끌어서 놓기 작업의 효과를 미리 봅니다. 그런 다음 줄임표 위로 끌 때 로 변환Brush할 수 있는 문자열 데이터가 포함되어 있는지 DataObject 확인합니다. 이 경우 Brush가 타원에 적용됩니다. DragLeave 이벤트 처리기에서 변경 사항을 되돌립니다. 데이터를 Brush로 변환할 수 없는 경우 아무 작업도 수행되지 않습니다.

private Brush _previousFill = null;
private void ellipse_DragEnter(object sender, DragEventArgs e)
{
    Ellipse ellipse = sender as Ellipse;
    if (ellipse != null)
    {
        // Save the current Fill brush so that you can revert back to this value in DragLeave.
        _previousFill = ellipse.Fill;
        
        // 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.
            BrushConverter converter = new BrushConverter();
            if (converter.IsValid(dataString))
            {
                Brush newFill = (Brush)converter.ConvertFromString(dataString);
                ellipse.Fill = newFill;
            }
        }
    }
}
Private _previousFill As Brush = Nothing
Private Sub Ellipse_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.DragEventArgs)
    Dim ellipse = TryCast(sender, Ellipse)
    If ellipse IsNot Nothing Then
        ' Save the current Fill brush so that you can revert back to this value in DragLeave.
        _previousFill = ellipse.Fill

        ' 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

설명

이 이벤트는 개체가 놓기 대상 역할을 하는 요소의 범위로 끌 때마다 한 번 발생합니다. 요소의 AllowDrop 속성 false이 이면 이 이벤트가 발생하지 않습니다.

이 이벤트 처리는 놓기 대상에 대해 선택 사항이며 모든 끌어서 놓기 시나리오에는 필요하지 않습니다. 애플리케이션에 적절한 경우 일반적으로 이 이벤트를 처리하여 끌어서 놓기 작업의 효과 미리 보기를 제공합니다. DragOver 이벤트에서 덮어쓰게 되므로 DragEnter 이벤트에서 DragEventArgs.Effects 속성을 설정하지 마세요.

라우팅 이벤트 정보

식별자 필드 DragEnterEvent
라우팅 전략 버블링
대리자 DragEventHandler

해당 터널링 이벤트가 PreviewDragEnter합니다.

적용 대상

추가 정보