I want to populate a label with the value from the Xamarin Forms TimePicker control. In my scenario, there a distinct difference between when a time has been selected and NO time has yet been selected (a value vs. the absence of a value), so I can't simply use the TimePicker's built-in label. Instead, I'm hiding the TimePicker in XAML, an invoking its Focus event to launch the control's UI.
I had assumed the events of the TimePicker control would be similar to those of the DatePicker control. But there is no TimeSelected event (like the DateSelected event of the DatePicker). And the PropertyChanged event -- which can be filtered to intercept changes to the Time property -- fires as the time picker RECEIVES focus (if initializing the time value in code...unlike the DatePicker, the TimePicker doesn't self-initialize), as well as when the control LOSES focus. This is a real conundrum!
The best I've been able to come up with so far is to...
1) Set a boolean flag variable when launching the time picker to indicate a time picker operation is in progress.
2) When the PropertyChanged event fires as the picker UI starts up/is initialized, exit immediately when if the boolean flag variable is true.
3) When the Unfocused event fires, change the boolean flag variable to false to indicate the picker operation is complete.
4) It seems the PropertyChanged event ALWAYS fires if the user clicks the OK button, even if the Time property valie didn't change. (Odd.) So as long as the boolean flag variable is NOT true, grab the Time value.
I think this should work reliably, but has anyone found a more straightforward solution to this problem? Am I missing something?
Are the Xamarin folks aware of this problem???
If the Xamarin folks are lurking hereabouts, the TimePicker control should really behave pretty much exactly like the DatePicker control. They're basically the same thing, after all!