Compartilhar via


DatePicker.SelectedDateChanged Evento

Definição

Ocorre quando o valor de data é alterado.

// Register
event_token SelectedDateChanged(TypedEventHandler<DatePicker, DatePickerSelectedValueChangedEventArgs const&> const& handler) const;

// Revoke with event_token
void SelectedDateChanged(event_token const* cookie) const;

// Revoke with event_revoker
DatePicker::SelectedDateChanged_revoker SelectedDateChanged(auto_revoke_t, TypedEventHandler<DatePicker, DatePickerSelectedValueChangedEventArgs const&> const& handler) const;
public event TypedEventHandler<DatePicker,DatePickerSelectedValueChangedEventArgs> SelectedDateChanged;
function onSelectedDateChanged(eventArgs) { /* Your code */ }
datePicker.addEventListener("selecteddatechanged", onSelectedDateChanged);
datePicker.removeEventListener("selecteddatechanged", onSelectedDateChanged);
- or -
datePicker.onselecteddatechanged = onSelectedDateChanged;
Public Custom Event SelectedDateChanged As TypedEventHandler(Of DatePicker, DatePickerSelectedValueChangedEventArgs) 
<DatePicker SelectedDateChanged="eventhandler" />

Tipo de evento

Exemplos

Aqui está um exemplo de um SelectedDateChanged manipulador de eventos. Para ver este exemplo com mais contexto, consulte Controles de calendário, data e hora – Use um seletor de data e um seletor de hora juntos.

<StackPanel>
    <DatePicker x:Name="arrivalDatePicker" Header="Arrival date"
                SelectedDateChanged="ArrivalDatePicker_SelectedDateChanged"/>
    <TextBlock x:Name="arrivalText"/>
</StackPanel>
DateTime arrivalDateTime;

private void ArrivalDatePicker_SelectedDateChanged(DatePicker sender, DatePickerSelectedValueChangedEventArgs args)
{
    if (arrivalDatePicker.SelectedDate != null)
    {
        if (VerifyDateIsFuture((DateTimeOffset)arrivalDatePicker.SelectedDate) == true)
        {
            arrivalDateTime = new DateTime(args.NewDate.Value.Year, args.NewDate.Value.Month, args.NewDate.Value.Day);

            arrivalText.Text = arrivalDateTime.ToString();
        }
        else
        {
            arrivalDatePicker.SelectedDate = null;
            arrivalText.Text = "Arrival date must be later than today.";
        }
    }
}

private bool VerifyDateIsFuture(DateTimeOffset date)
{
    if (date > DateTimeOffset.Now)
    {
        return true;
    }
    return false;
}

Comentários

Ao manipular esse evento, use as propriedades OldDate e NewDate dos dados de evento DatePickerSelectedValueChangedEventArgs para sua lógica. Essas propriedades usam tipos de dados diferentes dependendo da linguagem de programação (C# e Visual Basic usam System.DateTimeOffset; As extensões de componente do Visual C++ (C++/CX) usam Windows::Foundation::D ateTime).

Aplica-se a

Confira também