0

I have a DatePicker on a Page and would like to know whenever the DatePickerFlyout associated with the DatePicker is opened. This would be straightforward if I had a reference to the relevant DatePickerFlyout (DatePickerFlyout has Opened and Opening events) , but I can't seem to find one.

Flyouts (Popups) appear in the Visual Tree under PopupRoot so I thought I might listen for changes in the PopupRoot branch. But walking up the tree stops at the RootScrollViewer, one level below PopupRoot, so I can't reference that branch.

VisualTreeHelper.GetOpenPopupsForXamlRoot() returns a list of open Popups (which includes Flyouts) but only if the Flyout in question is actually open.

Any idea how I can find and work with the actual DatePickerFlyout object?

Thank you in advance.

aturnbul
  • 347
  • 2
  • 12
  • I tried but couldn't succeed. The closest thing might be just using the ``Tapped`` event of the ``DatePicker`` control. – Andrew KeepCoding Jan 11 '23 at 03:40
  • Thanks, @AndrewKeepCoding. I did figure out an extremely tortured way to determine when the `DatePickerFlyoutPresenter` is added to the `VisualTree`, but nothing for the `DataPickerFlyout`. It seems strange to me but `Flyout`s (and `Popup`s in general) don't seem to be connected in any way to the `UIElement`s that invoke them. – aturnbul Jan 11 '23 at 17:00
  • If you really need to work with the flyout, you could just create a custom control, implement it based on the actual ``DatePicker`` and show a ``Flyout`` based on the ``DatePickerFlyoutPresenter`` style. – Andrew KeepCoding Jan 12 '23 at 00:09
  • I've tried that but some of the characteristics must be set in code and override anything set in XAML (for example, the placeholder text of "month", "day", and "year") and I can't find the source for the `DatePicker` to look at what's going on. Overriding `OnApplyTemplate` doesn't help, either. Any idea where I can find the source? And thanks again for the help! – aturnbul Jan 12 '23 at 14:53
  • 1
    I mean, you can implement a ``DatePicker`` control yourself but using the styles from the actual ``DatePicker`` to have the same look. It's just a button with a flyout for date selection after all. – Andrew KeepCoding Jan 12 '23 at 15:33
  • I see what you mean. How silly of me. Excellent point - thanks. – aturnbul Jan 13 '23 at 03:10
  • My bad. I wasn't clear enough. – Andrew KeepCoding Jan 13 '23 at 03:18

0 Answers0