static DropDownButton() { var type = typeof(DropDownButton); DefaultStyleKeyProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(type)); System.Windows.Controls.ToolTipService.IsEnabledProperty.OverrideMetadata(typeof(DropDownButton), new FrameworkPropertyMetadata(null, CoerceToolTipIsEnabled)); KeyboardNavigation.ControlTabNavigationProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(KeyboardNavigationMode.Once)); KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle)); ToolTipService.Attach(type); PopupService.Attach(type); ContextMenuService.Attach(type); }
/// <summary> /// Invoked when an unhandled System.Windows.UIElement.PreviewMouseLeftButtonDown�routed /// event reaches an element in its route that is derived from this class. /// Implement this method to add class handling for this event. /// </summary> /// <param name="e">The System.Windows.Input.MouseButtonEventArgs that contains the event data. /// The event data reports that the left mouse button was pressed.</param> protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (((State == RibbonGroupBoxState.Collapsed) || (State == RibbonGroupBoxState.QuickAccess)) && (popup != null)) { e.Handled = true; if (!IsDropDownOpen) { IsDropDownOpen = true; } else { PopupService.RaiseDismissPopupEvent(this, DismissPopupMode.MouseNotOver); } } }
/// <summary> /// Called when the left mouse button is released. /// </summary> /// <param name="e">The event data for the <see cref="E:System.Windows.UIElement.MouseLeftButtonUp"/> event.</param> protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { if (e.ClickCount == 1) { if (this.IsSplited) { var buttonBorder = this.GetTemplateChild("PART_ButtonBorder") as Border; if (buttonBorder != null && PopupService.IsMousePhysicallyOver(buttonBorder)) { this.OnClick(); } } } base.OnMouseLeftButtonUp(e); }
/// <summary> /// Called when a <see cref="T:System.Windows.Controls.Button"/> is clicked. /// </summary> protected override void OnClick() { // Close popup on click //if ((IsDefinitive)&&(!HasItems)) PopupService.RaiseDismissPopupEvent(this, DismissPopupMode.Always); /*if (HasItems && IsSplited) * { * Border buttonBorder = GetTemplateChild("PART_ButtonBorder") as Border; * if ((buttonBorder != null) && (buttonBorder.IsMouseOver)) * { * if (IsDefinitive) PopupService.RaiseDismissPopupEvent(this, DismissPopupMode.Always); * } * } * else */ if ((IsDefinitive) && (!HasItems || IsSplited)) { PopupService.RaiseDismissPopupEvent(this, DismissPopupMode.Always); } base.OnClick(); }
/// <inheritdoc /> protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { if (e.ClickCount == 1) { if (this.IsSplited) { if (this.GetTemplateChild("PART_ButtonBorder") is Border buttonBorder && PopupService.IsMousePhysicallyOver(buttonBorder)) { this.OnClick(); } } else if (this.HasItems) { this.IsSubmenuOpen = !this.IsSubmenuOpen; } } base.OnMouseLeftButtonUp(e); }
/// <summary> /// Handles dismiss popup event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void OnDismissPopup(object sender, DismissPopupEventArgs e) { IDropDownControl control = sender as IDropDownControl; if (control == null) { return; } if (e.DismissMode == DismissPopupMode.Always) { if (Mouse.Captured == control) { Mouse.Capture(null); } // Debug.WriteLine("DropDown Closed"); control.IsDropDownOpen = false; } else { if ((control.IsDropDownOpen) && (!PopupService.IsMousePhysicallyOver(control.DropDownPopup.Child))) { if (Mouse.Captured == control) { Mouse.Capture(null); } // Debug.WriteLine("DropDown Closed"); control.IsDropDownOpen = false; } else { if ((control.IsDropDownOpen) && (Mouse.Captured != control)) { Mouse.Capture(sender as IInputElement, CaptureMode.SubTree); } if (control.IsDropDownOpen) { e.Handled = true; } } } }
/// <summary> /// Called when the left mouse button is released. /// </summary> /// <param name="e">The event data for the <see cref="E:System.Windows.UIElement.MouseLeftButtonUp"/> event.</param> protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { if (e.ClickCount == 1) { if (this.IsSplited) { Border buttonBorder = this.GetTemplateChild("PART_ButtonBorder") as Border; if ((buttonBorder != null) && (PopupService.IsMousePhysicallyOver(buttonBorder))) { /*if (Command != null) * { * RoutedCommand command = Command as RoutedCommand; * if (command != null) command.Execute(CommandParameter, CommandTarget); * else Command.Execute(CommandParameter); * }*/ this.OnClick(); } } } base.OnMouseLeftButtonUp(e); }
/// <summary> /// Invoked when an unhandled System.Windows.UIElement.PreviewMouseLeftButtonDown routed event /// reaches an element in its route that is derived from this class. Implement this method to add /// class handling for this event. /// </summary> /// <param name="e">The System.Windows.Input.MouseButtonEventArgs that contains the event data. /// The event data reports that the left mouse button was pressed.</param> protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { if (!buttonBorder.IsMouseOver) { return; } if (!IsDropDownOpen) { if (isFirstTime) { DropDownPopup.Opacity = 0; } if (!isFirstTime) { IsDropDownOpen = true; } } else { PopupService.RaiseDismissPopupEventAsync(this, DismissPopupMode.MouseNotOver); IsDropDownOpen = false; } e.Handled = true; if (isFirstTime) { isFirstTime = false; //IsDropDownOpen = false; Dispatcher.Invoke(DispatcherPriority.Send, (ThreadStart)(() => { IsDropDownOpen = true; DropDownPopup.Opacity = 1; })); } }
/// <inheritdoc /> protected override void OnClick() { // Close popup on click if (this.IsDefinitive) { PopupService.RaiseDismissPopupEvent(this, DismissPopupMode.Always); } // fix for #481 // We can't overwrite OnToggle because it's "internal protected"... if (string.IsNullOrEmpty(this.GroupName) == false) { // Only forward click if button is not checked to prevent wrong bound values if (this.IsChecked == false) { base.OnClick(); } } else { base.OnClick(); } }
/// <summary> /// Invoked when an unhandled System.Windows.UIElement.PreviewMouseLeftButtonDown /// event reaches an element in its route that is derived from this class. /// Implement this method to add class handling for this event. /// </summary> /// <param name="e">The System.Windows.Input.MouseButtonEventArgs that contains the event data. /// The event data reports that the left mouse button was pressed.</param> protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (ReferenceEquals(e.Source, this) == false || this.DropDownPopup == null) { return; } if (this.State == RibbonGroupBoxState.Collapsed || this.State == RibbonGroupBoxState.QuickAccess) { e.Handled = true; if (!this.IsDropDownOpen) { this.IsDropDownOpen = true; } else { PopupService.RaiseDismissPopupEventAsync(this, DismissPopupMode.MouseNotOver); } } }
private void OnListBoxSelectedChanged(object sender, SelectionChangedEventArgs e) { if (isSelectionChanged) { return; } isSelectionChanged = true; if (e.AddedItems != null && e.AddedItems.Count > 0) { // Remove selection from others noColorButton.IsChecked = false; automaticButton.IsChecked = false; for (int i = 0; i < listBoxes.Count; i++) { if (listBoxes[i] != sender) { listBoxes[i].SelectedItem = null; } } SelectedColor = (Color)e.AddedItems[0]; PopupService.RaiseDismissPopupEventAsync(this, DismissPopupMode.Always); } isSelectionChanged = false; }
/// <summary> /// Invoked when an unhandled System.Windows.UIElement.PreviewMouseLeftButtonDown routed event /// reaches an element in its route that is derived from this class. Implement this method to add /// class handling for this event. /// </summary> /// <param name="e">The System.Windows.Input.MouseButtonEventArgs that contains the event data. /// The event data reports that the left mouse button was pressed.</param> protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { if (!buttonBorder.IsMouseOver) { return; } if (!IsDropDownOpen) { if (isFirstTime) { DropDownPopup.Opacity = 0; } if (menuPanel != null) { if (scrollViewer != null /* && ResizeMode != ContextMenuResizeMode.None*/) { scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; } menuPanel.Width = double.NaN; menuPanel.Height = double.NaN;// Math.Min(menuPanel.MinHeight, MaxDropDownHeight); menuPanel.Loaded += OnMenuPanelLoaded; } if (!isFirstTime) { IsDropDownOpen = true; } } else { PopupService.RaiseDismissPopupEventAsync(this, DismissPopupMode.MouseNotOver); IsDropDownOpen = false; } e.Handled = true; if (isFirstTime) { isFirstTime = false; //IsDropDownOpen = false; Dispatcher.Invoke(DispatcherPriority.Send, (ThreadStart)(() => { if (menuPanel != null) { if (scrollViewer != null /* && ResizeMode != ContextMenuResizeMode.None*/) { scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; } menuPanel.Width = double.NaN; menuPanel.Height = double.NaN; menuPanel.Loaded += OnMenuPanelLoaded; } IsDropDownOpen = true; OnMenuPanelLoaded(null, null); DropDownPopup.Opacity = 1; })); } }
private void ClosePopups() { PopupService.RaiseDismissPopupEvent(Keyboard.FocusedElement, DismissPopupMode.Always); }
private void ClosePopups() { PopupService.RaiseDismissPopupEvent(Keyboard.FocusedElement, DismissPopupMode.Always, DismissPopupReason.ShowingKeyTips); }