1
votes

I have a native Date Picker in a windows phone app.
Using the DateChanged event I can perform actions when the user submits.

DatePicker.DateChanged += (o, args) => 
{
    var date = args.NewDate;
    // Do something with it
}

The problem I am facing is the event is not triggered if the user submits the date picker without changing the date.
Default value is set to today's date which makes it impossible to select this date.

Does anyone know how I can allow the user the select this date and perform actions after ?

Thanks for your help :)

1

1 Answers

0
votes

There is no particular way of getting an event fired when the date is not changed. As you said the date picker by default selects the current date, you can perform the action you want to if the user selects today's date in the OnNavigatedTo, Loaded, or DatePicker_Loaded event. A better way to do so is providing the DatePicker an invalid date something like 1Jan1947, this ways the user has to change the date else it'll be invalid. Also if you write the code you want on dateChanged event, it'll fire automatically as when the DatePicker is Loaded it sets the date from default to the current date.

What I would recommend

  1. is to use a binding property to hold a value and then performing the operations onPropertyChanged event of that property. This ways your logic is independent of your datePicker and you could write events for each time the dateTime property changes.

  2. Do remember to bind the datePicker's date property to the DateTime property in a TwoWay Mode and an UpdateSourceTrigger of PropertyChanged. This ways when you change the property from code behind the data would reflect in the datePicker and when you change the value in the datePicker, the data would be reflected in the code behind as well