/// <summary> /// PopupTimeSelectionModeProperty property changed handler. /// </summary> /// <param name="d">TimePickerPopup that changed its PopupTimeSelectionMode.</param> /// <param name="e">Event arguments.</param> private static void OnPopupTimeSelectionModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TimePickerPopup source = (TimePickerPopup)d; PopupTimeSelectionMode value = (PopupTimeSelectionMode)e.NewValue; if (!source.GetValidPopupTimeSelectionModes().Contains(value)) { // revert to old value source.SetValue(PopupTimeSelectionModeProperty, e.OldValue); string message = string.Format( CultureInfo.InvariantCulture, Properties.Resources.TimePicker_PopupTimeSelectionModeNotValid, value); throw new ArgumentOutOfRangeException("e", message); } // potentially flow back to parent. if (source.TimePickerParent != null && source.TimePickerParent.PopupTimeSelectionMode != value) { source.TimePickerParent.SetValue(TimePicker.PopupTimeSelectionModeProperty, value); } source.OnPopupTimeSelectionModeChanged((PopupTimeSelectionMode)e.OldValue, (PopupTimeSelectionMode)e.NewValue); source.UpdateVisualState(true); }
/// <summary> /// PopupMinutesIntervalProperty property changed handler. /// </summary> /// <param name="d">TimePicker that changed its PopupMinutesInterval.</param> /// <param name="e">Event arguments.</param> private static void OnPopupMinutesIntervalPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TimePickerPopup source = (TimePickerPopup)d; int oldValue = (int)e.OldValue; int newValue = (int)e.NewValue; if (newValue < 0 || newValue > 59) { // revert to old value source.SetValue(PopupMinutesIntervalProperty, e.OldValue); string message = string.Format( CultureInfo.InvariantCulture, Properties.Resources.TimeInput_PopupMinutesInterval_InvalidValue, newValue); throw new ArgumentOutOfRangeException("e", message); } // potentially flow back to parent. if (source.TimePickerParent != null && source.TimePickerParent.PopupMinutesInterval != newValue) { source.TimePickerParent.SetValue(TimePicker.PopupMinutesIntervalProperty, newValue); } source.OnPopupMinutesIntervalChanged(oldValue, newValue); }
/// <summary> /// CultureProperty property changed handler. /// </summary> /// <param name="d">TimeUpDown that changed its Culture.</param> /// <param name="e">Event arguments.</param> private static void OnCulturePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TimePickerPopup source = (TimePickerPopup)d; CultureInfo newValue = e.NewValue as CultureInfo; source.ActualTimeGlobalizationInfo.Culture = newValue; // potentially flow back to parent. if (source.TimePickerParent != null && source.TimePickerParent.Culture != source.ActualTimeGlobalizationInfo.Culture) { source.TimePickerParent.SetValue(TimePicker.CultureProperty, newValue); } source.OnCultureChanged(e.OldValue as CultureInfo, newValue); }
/// <summary> /// MaximumProperty property changed handler. /// </summary> /// <param name="d">TimeUpDown that changed its Maximum.</param> /// <param name="e">Event arguments.</param> private static void OnMaximumPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TimePickerPopup source = (TimePickerPopup)d; DateTime? oldValue = (DateTime?)e.OldValue; DateTime? newValue = (DateTime?)e.NewValue; // potentially flow back to parent. if (source.TimePickerParent != null && source.TimePickerParent.Maximum != newValue) { source.TimePickerParent.SetValue(TimePicker.MaximumProperty, newValue); } source._ignoreValueChange = true; source._timeCoercionHelper.ProcessMaximumChange(newValue); source._ignoreValueChange = false; source.OnMaximumChanged(oldValue, newValue); }
/// <summary> /// ValueProperty property changed handler. /// </summary> /// <param name="d">UpDownBase whose Value changed.</param> /// <param name="e">Event arguments.</param> private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TimePickerPopup source = (TimePickerPopup)d; // Ignore the change if requested if (source._ignoreValueChange) { // we do want to raise the event, but won't react to anything. source.OnValueChanged(new RoutedPropertyChangedEventArgs <DateTime?>(e.OldValue as DateTime?, e.NewValue as DateTime?)); return; } DateTime?oldValue = (DateTime?)e.OldValue; DateTime?newValue = (DateTime?)e.NewValue; // simulate pre and post events // The Value has already been changed when this function is called. // So if user's chaning event handler check Value, it will be the changed value. // This is confusing, because we are simulating pre event on the platform that doesn't natively support it. RoutedPropertyChangingEventArgs <DateTime?> changingArgs = new RoutedPropertyChangingEventArgs <DateTime?>(e.Property, oldValue, newValue, true); source.OnValueChanging(changingArgs); // workaround the class hierarchy for value coercion if (changingArgs.InCoercion) { } else if (!changingArgs.Cancel) { newValue = changingArgs.NewValue; RoutedPropertyChangedEventArgs <DateTime?> changedArgs = new RoutedPropertyChangedEventArgs <DateTime?>(oldValue, newValue); source.OnValueChanged(changedArgs); TimePickerPopupAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(source) as TimePickerPopupAutomationPeer; if (peer != null) { peer.RaiseValueAutomationEvent(oldValue, newValue); } } else { // revert back to old value if an event handler canceled the changing event. source._ignoreValueChange = true; source.Value = oldValue; source._ignoreValueChange = false; } }
/// <summary> /// FormatProperty property changed handler. /// </summary> /// <param name="d">TimePickerPopup that changed its Format.</param> /// <param name="e">Event arguments.</param> private static void OnFormatPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TimePickerPopup source = (TimePickerPopup)d; ITimeFormat value = e.NewValue as ITimeFormat; // potentially flow back to parent. if (source.TimePickerParent != null && source.TimePickerParent.Format != value) { source.TimePickerParent.SetValue(TimePicker.FormatProperty, value); } if (e.NewValue != null) { // no need for cache any more. source._actualFormat = null; } source.OnFormatChanged(e.OldValue as ITimeFormat, value); }
/// <summary> /// TimeGlobalizationInfoProperty property changed handler. /// </summary> /// <param name="d">TimeUpDown that changed its TimeGlobalizationInfo.</param> /// <param name="e">Event arguments.</param> private static void OnTimeGlobalizationInfoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TimePickerPopup source = (TimePickerPopup)d; TimeGlobalizationInfo newValue = e.NewValue as TimeGlobalizationInfo; // potentially flow back to parent. if (source.TimePickerParent != null && source.TimePickerParent.TimeGlobalizationInfo != newValue) { source.TimePickerParent.SetValue(TimePicker.TimeGlobalizationInfoProperty, newValue); } if (newValue != null) { newValue.Culture = source.Culture; source._actualTimeGlobalizationInfo = null; // no need for default any more. } source.OnTimeGlobalizationInfoChanged(e.OldValue as TimeGlobalizationInfo, newValue); }
/// <summary> /// Initializes a new instance of the /// <see cref="TimePickerPopupAutomationPeer"/> class. /// </summary> /// <param name="owner">The TimePickerPopup that is associated to this /// AutomationPeer.</param> protected TimePickerPopupAutomationPeer(TimePickerPopup owner) : base(owner) { }
/// <summary> /// Instantiates the template. /// </summary> /// <remarks>Will only use template if Popup is not set.</remarks> private void InstantiatePopupFromTemplate() { // template will only be used when no Popup is set. if (_isInitialized && Popup == null && PopupTemplate != null) { // unregister oldPopup UnregisterPopup(ActualTimePickerPopup); // instantiate template TimePickerPopup popup = PopupTemplate.LoadContent() as TimePickerPopup; if (popup != null) { _instantiatedPopupFromTemplate = popup; // register RegisterPopup(ActualTimePickerPopup); } } }
private void UnregisterPopup(TimePickerPopup popup) { if (popup != null) { popup.TimePickerParent = null; } }
/// <summary> /// Called when a new Popup is set. /// </summary> /// <param name="popup">The new value.</param> private void RegisterPopup(TimePickerPopup popup) { if (popup != null) { if (PopupPlaceHolderPart != null) { PopupPlaceHolderPart.Content = popup; } popup.TimePickerParent = this; if (!popup.GetValidPopupTimeSelectionModes().Contains(PopupTimeSelectionMode)) { // silently coerce PopupTimeSelectionMode = popup.PopupTimeSelectionMode; } } }