/// <summary> /// PopupButtonModeProperty property changed handler. /// </summary> /// <param name="d">Picker that changed its PopupButtonMode.</param> /// <param name="e">Event arguments.</param> private static void OnPopupButtonModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Picker source = (Picker)d; ClickMode newValue = (ClickMode)e.NewValue; if (newValue != ClickMode.Hover && newValue != ClickMode.Press && newValue != ClickMode.Release) { // revert to old value source.SetValue(PopupButtonModeProperty, e.OldValue); // todo: move to resource string message = string.Format( CultureInfo.InvariantCulture, "Invalid value: {0}", newValue); throw new ArgumentOutOfRangeException("e", message); } if (source.DropDownToggleButton != null) { source.DropDownToggleButton.ClickMode = newValue; } }
private static void OnMaxDropDownHeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Picker source = (Picker)d; if (source._ignorePropertyChange) { source._ignorePropertyChange = false; return; } double newValue = (double)e.NewValue; // Revert to the old value if invalid (negative) if (newValue < 0) { source._ignorePropertyChange = true; source.SetValue(e.Property, e.OldValue); throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.Picker_OnMaxDropDownHeightPropertyChanged_InvalidValue, e.NewValue), "value"); } source.OnMaxDropDownHeightChanged(newValue); }
/// <summary> /// IsDropDownOpenProperty property changed handler. /// </summary> /// <param name="d">Picker that changed its IsDropDownOpen.</param> /// <param name="e">Event arguments.</param> private static void OnIsDropDownOpenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Picker source = (Picker)d; // Ignore the change if requested if (source._ignorePropertyChange) { source._ignorePropertyChange = false; return; } bool oldValue = (bool)e.OldValue; bool newValue = (bool)e.NewValue; bool delayedClosingVisual = source._popupClosedVisualState; RoutedPropertyChangingEventArgs <bool> args = new RoutedPropertyChangingEventArgs <bool>(e.Property, oldValue, newValue, true); PickerAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(source) as PickerAutomationPeer; if (peer != null) { peer.RaiseExpandCollapseAutomationEvent(oldValue, newValue); } if (newValue) { // Opening source.OnDropDownOpening(args); // Opened if (!args.Cancel) { source.OpenDropDown(oldValue, newValue); } } else { // Closing source.OnDropDownClosing(args); // Immediately close the drop down window: // When a popup closed visual state is present, the code path is // slightly different and the actual call to CloseDropDown will // be called only after the visual state's transition is done if (!args.Cancel && !delayedClosingVisual) { source.CloseDropDown(oldValue, newValue); } } // If canceled, revert the value change if (args.Cancel) { // source._ignorePropertyChange = true; source.SetValue(e.Property, oldValue); } // Closing call when visual states are in use if (delayedClosingVisual) { source.UpdateVisualState(true); } }