DragDrop.DragEnter Evento Anexado

Definição

Ocorre quando um objeto é arrastado para dentro dos limites de um elemento que atua como alvo de queda.

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

Exemplos

O exemplo seguinte mostra o DragEnter gestor de eventos para um Ellipse elemento. Este código antecipa os efeitos da operação de arrastar e largar ao guardar o pincel atual Fill . Depois verifica se o DataObject ser arrastado sobre a elipse contém dados de cadeia que podem ser convertidos para um Brush. Se sim, aplica-se à Brush elipse. A alteração é revertida no DragLeave handler de eventos. Se os dados não puderem ser convertidos para um Brush, não é realizada nenhuma ação.

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

Observações

Este evento é levantado uma vez cada vez que um objeto é arrastado para dentro dos limites de um elemento que atua como alvo de queda. Este evento não é elevado se a propriedade do AllowDrop elemento for false.

Gerir este evento é opcional para o alvo de largada, e não é necessário para todos os cenários de arrastar e largar. Normalmente, trata este evento para fornecer uma pré-visualização dos efeitos da operação de arrastar e largar, se apropriado para a sua aplicação. Não defina a DragEventArgs.Effects propriedade no DragEnter evento, pois será sobrescrita no DragOver evento.

Informação sobre Eventos Roteados

Iteme Value
Campo identificador DragEnterEvent
Estratégia de encaminhamento Borbulhar
Delegar DragEventHandler

O evento correspondente de tunelamento é PreviewDragEnter.

Aplica-se a

Ver também