DragDrop.DragEnter Evento anexado

Definição

Ocorre quando um objeto é arrastado para dentro dos limites de um elemento que está atuando como uma reprodução automática.

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

Exemplos

O exemplo a seguir mostra o DragEnter manipulador de eventos de um Ellipse elemento . Esse código visualiza os efeitos da operação de arrastar e soltar salvando o pincel atual Fill . Em seguida, ele verifica se o DataObject que está sendo arrastado sobre a elipse contém dados de cadeia de caracteres que podem ser convertidos em um Brush. Nesse caso, o Brush é aplicado à elipse. A alteração é revertida no DragLeave manipulador de eventos. Se os dados não puderem ser convertidos em um Brush, nenhuma ação será executada.

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

Comentários

Esse evento é gerado uma vez cada vez que um objeto é arrastado para os limites de um elemento que está agindo como um destino de soltar. Esse evento não será gerado se a propriedade do AllowDrop elemento for false.

A manipulação desse evento é opcional para o destino de soltar e não é necessária para todos os cenários de arrastar e soltar. Normalmente, esse evento é manipulado para fornecer uma visualização dos efeitos da operação do tipo "arrastar e soltar", se apropriado para o aplicativo. Não defina a DragEventArgs.Effects propriedade no DragEnter evento, pois ela será substituída no DragOver evento.

Informações de evento encaminhado

Campo Identificador DragEnterEvent
Estratégia de roteamento Borbulhando
Delegar DragEventHandler

O evento de túnel correspondente é PreviewDragEnter.

Aplica-se a

Confira também