PopupButton Class
Represents a button control that supports display of popups or context menus, and can render in multiple display modes.
[TemplatePart(Name = "PART_IndicatorArea", Type = typeof(UIElement))]
[TemplatePart(Name = "PART_Popup", Type = typeof(Popup))]
public class PopupButton : Button, IPopupAnchor
- Inheritance:
- object Visual UIElement FrameworkElement Control ContentControl ButtonBase Button object
- Derived:
- BarMenuGalleryFilterButton RibbonGroupCollapsedButton RibbonQuickAccessToolBarOverflowButton StandaloneToolBarOverflowButton BreadcrumbButtonBase
- Implements:
- IPopupAnchor
Constructors
PopupButton()
Initializes an instance of the class.
public PopupButton()
Properties
ClosePopupCommand
The ICommand that can close the popup.
CornerRadius
The CornerRadius for the control's border.
DisplayMode
A PopupButtonDisplayMode that describes how the content and popup indicator are rendered.
public PopupButtonDisplayMode DisplayMode { get; set; }
Property Value
- PopupButtonDisplayMode:
The default value is
Merged.
HasDropShadow
Indicates whether the popup will display a drop-shadow effect.
public bool HasDropShadow { get; set; }
Property Value
- bool:
trueif the popup will display a drop-shadow effect; otherwise,false. The default value istrue.
Remarks
Setting this property to true has no effect if the SystemParameters.DropShadow property is false.
IsAutoFocusOnOpenEnabled
Indicates whether the popup content will be automatically focused when the popup is opened.
public bool IsAutoFocusOnOpenEnabled { get; set; }
Property Value
- bool:
trueif the popup content will be automatically focused when the popup is opened; otherwise,false. The default value istrue.
IsPopupOpen
Indicates whether a child popup is open.
public bool IsPopupOpen { get; set; }
Property Value
- bool:
trueif the a child popup is open; otherwise,false.
IsTransparencyModeEnabled
Indicates whether transparency mode is enabled, meaning the button has no visible background until the pointer is over it.
public bool IsTransparencyModeEnabled { get; set; }
Property Value
- bool:
trueif transparency mode is enabled; otherwise,false. The default value isfalse.
LogicalChildren
Gets an enumerator to the content control's logical child elements.
protected override IEnumerator LogicalChildren { get; }
Property Value
- IEnumerator:
An enumerator. The default value is
null.
Popup
The popup defined in the template.
PopupAllowsTransparency
Indicates whether the popup allows transparency.
public bool PopupAllowsTransparency { get; set; }
Property Value
- bool:
trueif transparency is allowed; otherwise,false. The default value istrue.
Remarks
When this property is set to false, interop content will be able to render on the popup.
PopupAnimation
The PopupAnimation for the opening and closing of the associated popup.
PopupBackground
The Brush for the popup's background.
public Brush? PopupBackground { get; set; }
Property Value
Remarks
This property is only used when PopupContent is specified.
PopupBorderBrush
The Brush for the popup's border.
public Brush? PopupBorderBrush { get; set; }
Property Value
Remarks
This property is only used when PopupContent is specified.
PopupBorderThickness
The Thickness for the popup's border.
public Thickness PopupBorderThickness { get; set; }
Property Value
Remarks
This property is only used when PopupContent is specified.
PopupContent
The content that is displayed on the button's Popup.
public object? PopupContent { get; set; }
Property Value
Remarks
This can be any object, including panels of multiple controls. The PopupContentTemplate and/or PopupContentTemplateSelector properties can be used to customize the display of data objects (non-UI elements).
The PopupMenu property takes precedence over this property. Therefore, if PopupMenu is set, this property is ignored.
PopupContentTemplate
The DataTemplate to use for the PopupContent.
public DataTemplate? PopupContentTemplate { get; set; }
Property Value
Remarks
This property is only useful if your popup content is a data object and not a UI element.
The PopupMenu property takes precedence over this property. Therefore, if PopupMenu is set, this property is ignored.
PopupContentTemplateSelector
The DataTemplateSelector to use for the PopupContent.
public DataTemplateSelector? PopupContentTemplateSelector { get; set; }
Property Value
Remarks
This property is only useful if your popup content is a data object and not a UI element.
The PopupMenu property takes precedence over this property. Therefore, if PopupMenu is set, this property is ignored.
PopupCornerRadius
The CornerRadius for the popup's border.
public CornerRadius PopupCornerRadius { get; set; }
Property Value
Remarks
This property is only used when PopupContent is specified.
PopupHorizontalOffset
The horizontal distance between the target origin and the popup alignment point.
PopupIndicator
The object used in the indicator portion of the PopupButton.
PopupIndicatorTemplate
The DataTemplate used to present the indicator portion of the PopupButton.
PopupIndicatorToolTip
The tool-tip object that is displayed for the popup indicator element.
[Localizability(LocalizationCategory.ToolTip)]
public object? PopupIndicatorToolTip { get; set; }
Property Value
PopupMenu
The popup menu displayed by the popup anchor.
public ContextMenu? PopupMenu { get; set; }
Property Value
Remarks
This property takes precedence over the PopupContent-related properties. Therefore, if this property is set, the PopupContent-related properties are ignored.
PopupMenuDataContext
The the data context for the PopupMenu when it participates in data binding.
public object? PopupMenuDataContext { get; set; }
Property Value
- object:
The default style binds this property to the
PopupButton.DataContext.
Remarks
The DataContext property of the PopupMenu is bound to this property, if and only if
the DataContext property was not already set on the ContextMenu.
PopupPadding
The Thickness of the popup's padding.
public Thickness PopupPadding { get; set; }
Property Value
Remarks
This property is only used when PopupContent is specified.
PopupPlacement
A PlacementMode indicating where the popup appears relative to the button.
public PlacementMode PopupPlacement { get; set; }
Property Value
- PlacementMode:
The default value is
Bottom.
PopupVerticalOffset
The vertical distance between the target origin and the popup alignment point.
StaysOpen
A value that indicates whether the Popup closes when the control is no longer in focus.
public bool StaysOpen { get; set; }
Property Value
- bool:
trueif the Popup closes when the control is no longer in focus; otherwise,false. The default isfalse.
Remarks
This property has no effect when using PopupMenu.
Methods
FocusWithin()
Focuses the first focusable descendant within the button's template, usually a root Grid that is flagged as focusable.
protected bool FocusWithin()
Returns
- bool:
trueif a focusable descendant was found and focused; otherwise,false.
Remarks
This concept is necessary since various places within native ButtonBase code such as on mouse capture loss will blur focus if the button itself has focus.
OnApplyTemplate()
When overridden in a derived class, is invoked whenever application code or internal processes call ApplyTemplate().
public override void OnApplyTemplate()
OnClick()
Called when a Button is clicked.
protected override void OnClick()
OnCreateAutomationPeer()
Creates an appropriate ButtonAutomationPeer for this control as part of the WPF infrastructure.
protected override AutomationPeer OnCreateAutomationPeer()
Returns
- AutomationPeer:
A ButtonAutomationPeer for this control.
OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs)
Invoked just before the IsKeyboardFocusWithinChanged event is raised by this element. Implement this method to add class handling for this event.
protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | DependencyPropertyChangedEventArgs | A System.Windows.DependencyPropertyChangedEventArgs that contains the event data. |
OnKeyDown(KeyEventArgs)
Provides class handling for the KeyDown routed event that occurs when the user presses a key while this control has focus.
protected override void OnKeyDown(KeyEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | KeyEventArgs | The event data. |
OnKeyUp(KeyEventArgs)
Provides class handling for the KeyUp routed event that occurs when the user releases a key while this control has focus.
protected override void OnKeyUp(KeyEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | KeyEventArgs | The event data for the KeyUp event. |
OnMouseLeftButtonDown(MouseButtonEventArgs)
Provides class handling for the MouseLeftButtonDown routed event that occurs when the left mouse button is pressed while the mouse pointer is over this control.
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseButtonEventArgs | The event data. |
OnMouseLeftButtonUp(MouseButtonEventArgs)
Provides class handling for the MouseLeftButtonUp routed event that occurs when the left mouse button is released while the mouse pointer is over this control.
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseButtonEventArgs | The event data. |
OnMouseWheel(MouseWheelEventArgs)
Invoked when an unhandled System.Windows.Input.Mouse.MouseWheel attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
protected override void OnMouseWheel(MouseWheelEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseWheelEventArgs | The MouseWheelEventArgs that contains the event data. |
OnPopupClosed(RoutedEventArgs)
Occurs when the IsPopupOpen property changes to false.
protected virtual void OnPopupClosed(RoutedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | RoutedEventArgs | The |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnPopupMenuChanged(ContextMenu?, ContextMenu?)
Occurs after the PopupMenu property value changed.
protected virtual void OnPopupMenuChanged(ContextMenu? oldValue, ContextMenu? newValue)
| Parameter | Type | Description |
|---|---|---|
| oldValue | ContextMenu | The old value. |
| newValue | ContextMenu | The new value. |
OnPopupOpened(RoutedEventArgs)
Occurs when the IsPopupOpen property changes to true.
protected virtual void OnPopupOpened(RoutedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | RoutedEventArgs | The |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
OnPopupOpening(CancelRoutedEventArgs)
Occurs before the IsPopupOpen property changes to true.
protected virtual void OnPopupOpening(CancelRoutedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | CancelRoutedEventArgs | The |
Remarks
This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.
Events
PopupClosed
Occurs when the IsPopupOpen property changes to false.
PopupOpened
Occurs when the IsPopupOpen property changes to true.
PopupOpening
Occurs before the IsPopupOpen property changes to true.
public event EventHandler<CancelRoutedEventArgs> PopupOpening
Event Type
Fields
CornerRadiusProperty
Defines the CornerRadius property.
public static readonly DependencyProperty CornerRadiusProperty
DisplayModeProperty
Defines the DisplayMode property.
public static readonly DependencyProperty DisplayModeProperty
HasDropShadowProperty
Defines the HasDropShadow property.
public static readonly DependencyProperty HasDropShadowProperty
IsAutoFocusOnOpenEnabledProperty
Defines the IsAutoFocusOnOpenEnabled property.
public static readonly DependencyProperty IsAutoFocusOnOpenEnabledProperty
IsPopupOpenProperty
Defines the IsPopupOpen property.
public static readonly DependencyProperty IsPopupOpenProperty
IsTransparencyModeEnabledProperty
Defines the IsTransparencyModeEnabled property.
public static readonly DependencyProperty IsTransparencyModeEnabledProperty
PopupAllowsTransparencyProperty
Defines the PopupAllowsTransparency property.
public static readonly DependencyProperty PopupAllowsTransparencyProperty
PopupAnimationProperty
Defines the PopupAnimation property.
public static readonly DependencyProperty PopupAnimationProperty
PopupBackgroundProperty
Defines the PopupBackground property.
public static readonly DependencyProperty PopupBackgroundProperty
PopupBorderBrushProperty
Defines the PopupBorderBrush property.
public static readonly DependencyProperty PopupBorderBrushProperty
PopupBorderThicknessProperty
Defines the PopupBorderThickness property.
public static readonly DependencyProperty PopupBorderThicknessProperty
PopupClosedEvent
Defines the PopupClosed event.
public static readonly RoutedEvent PopupClosedEvent
PopupContentProperty
Defines the PopupContent property.
public static readonly DependencyProperty PopupContentProperty
PopupContentTemplateProperty
Defines the PopupContentTemplate property.
public static readonly DependencyProperty PopupContentTemplateProperty
PopupContentTemplateSelectorProperty
Defines the PopupContentTemplateSelector property.
public static readonly DependencyProperty PopupContentTemplateSelectorProperty
PopupCornerRadiusProperty
Defines the PopupCornerRadius property.
public static readonly DependencyProperty PopupCornerRadiusProperty
PopupHorizontalOffsetProperty
Defines the PopupHorizontalOffset property.
public static readonly DependencyProperty PopupHorizontalOffsetProperty
PopupIndicatorProperty
Defines the PopupIndicator property.
public static readonly DependencyProperty PopupIndicatorProperty
PopupIndicatorTemplateProperty
Defines the PopupIndicatorTemplate property.
public static readonly DependencyProperty PopupIndicatorTemplateProperty
PopupIndicatorToolTipProperty
Defines the PopupIndicatorToolTip property.
public static readonly DependencyProperty PopupIndicatorToolTipProperty
PopupMenuDataContextProperty
Defines the PopupMenuDataContext property.
public static readonly DependencyProperty PopupMenuDataContextProperty
PopupMenuProperty
Defines the PopupMenu property.
public static readonly DependencyProperty PopupMenuProperty
PopupOpenedEvent
Defines the PopupOpened event.
public static readonly RoutedEvent PopupOpenedEvent
PopupOpeningEvent
Defines the PopupOpening event.
public static readonly RoutedEvent PopupOpeningEvent
PopupPaddingProperty
Defines the PopupPadding property.
public static readonly DependencyProperty PopupPaddingProperty
PopupPlacementProperty
Defines the PopupPlacement property.
public static readonly DependencyProperty PopupPlacementProperty
PopupVerticalOffsetProperty
Defines the PopupVerticalOffset property.
public static readonly DependencyProperty PopupVerticalOffsetProperty
StaysOpenProperty
Defines the StaysOpen property.
public static readonly DependencyProperty StaysOpenProperty