private static void OnMinDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FXDatePicker datepicker = (FXDatePicker)d; datepicker.CoerceValue(MaxDateProperty); datepicker.CoerceValue(SelectedDateTimeProperty); }
/// <summary> /// If we (or one of our children) are clicked, claim the focus /// </summary> 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; } } } }
private static void OnNullValueTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FXDatePicker datepicker = (FXDatePicker)d; if (!datepicker.SelectedDateTime.HasValue) { datepicker.DoFormat(null); } }
private static object CoerceMaxDate(DependencyObject d, object value) { FXDatePicker datepicker = (FXDatePicker)d; DateTime newValue = (DateTime)value; DateTime min = datepicker.MinDate; if (newValue < min) { return(min); } return(value); }
/// <summary> /// Coerce IsDropDownOpen with IsLoaded, so set IsDropDownOpen to true before UI ready can work /// </summary> private static object CoerceIsDropDownOpen(DependencyObject d, object value) { if ((bool)value) { FXDatePicker dp = (FXDatePicker)d; if (!dp.IsLoaded) { //Defer setting IsDropDownOpen to true after Loaded event is fired to show popup window correctly dp.Loaded += dp.OpenOnLoad; return(false); } } return(value); }
private static void OnSelectedDateTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FXDatePicker datepicker = (FXDatePicker)d; DateTime? oldValue = (DateTime?)e.OldValue; DateTime? newValue = (DateTime?)e.NewValue; //Invalid the IsValid and Text property when SelectedDateTime is changed datepicker.SetValue(IsValidPropertyKey, newValue.HasValue); datepicker.DoFormat(newValue); if (datepicker.MonthView != null) { datepicker.MonthView.SelectedDateTime = newValue; } RoutedPropertyChangedEventArgs <DateTime?> routedArgs = new RoutedPropertyChangedEventArgs <DateTime?>(oldValue, newValue, SelectedDateTimeChangedEvent); datepicker.OnSelectedDateTimeChanged(routedArgs); }
private static object CoerceSelectedDateTime(DependencyObject d, object value) { FXDatePicker datepicker = (FXDatePicker)d; if (value != null) { DateTime newValue = (DateTime)value; DateTime min = datepicker.MinDate; if (newValue < min) { return(min); } DateTime max = datepicker.MaxDate; if (newValue > max) { return(max); } } return(value); }
private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var datepicker = (FXDatePicker)d; if (datepicker.MonthView != null) { datepicker.MonthView.ShowTodayButton = datepicker.ShowTodayButton; datepicker.MonthView.ShowEmptyButton = datepicker.ShowEmptyButton; datepicker.MonthView.ShowWeekDayNames = datepicker.ShowWeekDayNames; } if ((bool)e.NewValue) { //Remember the previous SelectedDateTime for cancel action (Key.Escape) datepicker.prevValue = datepicker.SelectedDateTime; if (datepicker.MonthView != null && datepicker.SelectedDateTime != datepicker.MonthView.SelectedDateTime) { datepicker.MonthView.SelectedDateTime = datepicker.SelectedDateTime; } // When the drop down opens, take capture Mouse.Capture(datepicker, CaptureMode.SubTree); // Popup.IsOpen is databound to IsDropDownOpen. We don't know // if IsDropDownOpen will be invalidated before Popup.IsOpen. // If we are invalidated first and we try to focus the item, we // might succeed. When the popup finally opens, Focus // will be sent to null because Core doesn't know what else to do. // So, we must focus the element only after we are sure the popup // has opened. We will queue an operation (at Send priority) to // do this work -- this is the soonest we can make this happen. if (datepicker.MonthView != null && datepicker.SelectedDateTime.HasValue) { datepicker.Dispatcher.BeginInvoke(DispatcherPriority.Send, (DispatcherOperationCallback) delegate(object arg) { FXDatePicker dp = (FXDatePicker)arg; if (dp.IsKeyboardFocusWithin) { FXMonthViewItem item = dp.MonthView.GetMonthViewItemFromDate(dp.SelectedDateTime.Value); if (item != null) { item.Focus(); } } return(null); }, datepicker); } datepicker.OnDropDownOpened(new RoutedEventArgs(DropDownOpenedEvent)); } else { // If focus is within the subtree, make sure we have the focus so that focus isn't in the disposed hwnd if (datepicker.IsKeyboardFocusWithin) { // If use Mouse to select a date, DateSelectionChanged is fired in ListBox.MakeSingleSelection // Then ListBoxItem.Focus() will be called which will grab the focus from FXDatePicker // So use Dispatcher.BeginInvoke to set Focus to FXDatePicker after ListBoxItem.Focus() datepicker.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (DispatcherOperationCallback) delegate(object arg) { FXDatePicker dp = (FXDatePicker)arg; if (dp.IsKeyboardFocusWithin) { dp.Focus(); } return(null); }, datepicker); if (datepicker.HasCapture) { // It's not editable, make sure the datepicker has focus datepicker.Focus(); } } if (datepicker.HasCapture) { Mouse.Capture(null); } datepicker.OnDropDownClosed(new RoutedEventArgs(DropDownClosedEvent)); } }
/// <summary> /// Creates a new instance of FXDatePickerAutomationPeer /// </summary> /// <param name="owner"></param> public FXDatePickerAutomationPeer(FXDatePicker owner) : base(owner) { }