Jaa


DatePicker.DateChanged Event

Definition

Occurs when the date value is changed.

// Register
event_token DateChanged(EventHandler<DatePickerValueChangedEventArgs> const& handler) const;

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

// Revoke with event_revoker
DatePicker::DateChanged_revoker DateChanged(auto_revoke_t, EventHandler<DatePickerValueChangedEventArgs> const& handler) const;
public event System.EventHandler<DatePickerValueChangedEventArgs> DateChanged;
function onDateChanged(eventArgs) { /* Your code */ }
datePicker.addEventListener("datechanged", onDateChanged);
datePicker.removeEventListener("datechanged", onDateChanged);
- or -
datePicker.ondatechanged = onDateChanged;
Public Custom Event DateChanged As EventHandler(Of DatePickerValueChangedEventArgs) 
<DatePicker DateChanged="eventhandler" />

Event Type

Examples

Here's an example of a DateChanged event handler.

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

private void ArrivalDatePicker_DateChanged(object sender, DatePickerValueChangedEventArgs e)
{
    if (VerifyDateIsFuture(arrivalDatePicker.Date) == true)
    {
        arrivalDateTime = new DateTime(e.NewDate.Year, e.NewDate.Month, e.NewDate.Day);
        arrivalText.Text = string.Format("Thank you. Your arrival is set for {0}.",
                                         arrivalDateTime.Date.ToString("D"));
    }
    else
    {
        arrivalText.Text = "Arrival date must be later than today.";
    }
}

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

Remarks

When you handle this event, use the OldDate and NewDate properties of the DatePickerValueChangedEventArgs event data for your logic. These properties use different data types depending on your programming language (C# and Visual Basic use System.DateTimeOffset; Visual C++ component extensions (C++/CX) uses Windows::Foundation::DateTime).

Applies to

See also