private static void OnMouseButtonDown(object sender, MouseButtonEventArgs e)
{
FXDatePicker datepicker = (FXDatePicker)sender;
e.Handled = true;
if (Mouse.Captured == datepicker && e.OriginalSource == datepicker)
{
// When we have capture, all clicks off the popup will have the datepicker as
// the OriginalSource. So when the original source is the datepicker, that
// means the click was off the popup and we should dismiss.
datepicker.IsDropDownOpen = false;
}
else
{
// If mouse click the selected date, close the popup
FrameworkElement fe = e.OriginalSource as FrameworkElement;
if (fe != null && fe.DataContext is CalendarDay)
{
if (datepicker.SelectedDateTime.HasValue && datepicker.SelectedDateTime.Value == ((CalendarDay)fe.DataContext).Date)
{
datepicker.IsDropDownOpen = false;
}
}
}
}