Search code examples
windows-phone-7silverlight-toolkitwindows-phone-7.1

Programmatically show the popup from a DatePicker


I'm using the DatePicker from the Silverlight Toolkit on Mango

I want to programmatically display the date picker full mode display, but I can't see any API hook to do that at the moment.

Is this possible? or do I have to implement this myself by (intelligently) writing a new control?


Solution

  • Sadly Matt was right - there's no public or protected API to hack into and security prevents the use of Reflection - so I've +1'd his answer... and a full answer is:

    • take the files from Silverlight.codeplex.com
    • either use the whole project or create your own library with just DatePicker.cs, DateTimePickerBase.cs and the DatePicker Style template from Generic.xaml
    • in your DateTimePickerBase, add:

      public event EventHandler<EventArgs> PopupClosedByDateSelection;
      
    • in ClosePickerPage() inside PopupClosedByDateSelection inside the if(_dateTimePickerPage.Value.HasValue) block, add:

                  if (PopupClosedByDateSelection != null)
                      PopupClosedByDateSelection(this, EventArgs.Empty);
      

    This seems to work for the Back button case as well as for the cancel and OK cases.