In This Article

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, DUCE.IResource, IAnimatable, IFrameworkInputElement, IInputElement, ISupportInitialize, IHaveResources, IQueryAmbient, IAddChild, ICommandSource, IPopupAnchor
Inheritance:
Object DispatcherObject DependencyObject Visual UIElement FrameworkElement Control ContentControl ButtonBase Button Object
Derived:
BreadcrumbButtonBase
Implements:
IPopupAnchor

Constructors

PopupButton()

public PopupButton()

Properties

ClosePopupCommand

Gets the ICommand that can close the popup.

public static RoutedCommand ClosePopupCommand { get; }

Property Value

RoutedCommand:

The ICommand that can close the popup.

CornerRadius

Gets or sets the CornerRadius for the control's border.

public CornerRadius CornerRadius { get; set; }

Property Value

CornerRadius:

The CornerRadius for the control's border.

DisplayMode

Gets or sets a PopupButtonDisplayMode that describes how the content and popup indicator are rendered.

public PopupButtonDisplayMode DisplayMode { get; set; }

Property Value

PopupButtonDisplayMode:

A PopupButtonDisplayMode that describes how the content and popup indicator are rendered. The default value is Merged.

HasDropShadow

Gets or sets whether the popup will display a drop-shadow effect.

public bool HasDropShadow { get; set; }

Property Value

Boolean:

true if the popup will display a drop-shadow effect; otherwise, false. The default value is true.

Remarks

Setting this property to true has no effect if the SystemParameters.DropShadow property is false.

IsAutoFocusOnOpenEnabled

Gets or sets a value indicating whether the popup content will be automatically focused when the popup is opened.

public bool IsAutoFocusOnOpenEnabled { get; set; }

Property Value

Boolean:

true if the popup content will be automatically focused when the popup is opened; otherwise, false. The default value is true.

IsPopupOpen

Gets or sets whether the popup is currently displayed.

public bool IsPopupOpen { get; set; }

Property Value

Boolean:

true if the popup is currently displayed; otherwise, false.

IsTransparencyModeEnabled

Gets or sets a value indicating 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

Boolean:

true if transparency mode is enabled; otherwise, false. The default value is false.

LogicalChildren

Gets an enumerator for logical child elements of this element.

protected override IEnumerator LogicalChildren { get; }

Property Value

IEnumerator:

An enumerator for logical child elements of this element.

Popup

Gets the popup defined in the template.

protected Popup Popup { get; set; }

Property Value

Popup:

The popup defined in the template.

PopupAllowsTransparency

Gets or sets a value for the popup's AllowTransparency property.

public bool PopupAllowsTransparency { get; set; }

Property Value

Boolean:

true if transparency is allowed; otherwise, false. The default value is true.

Remarks

When this property is set to false, interop content will be able to render on the popup.

PopupAnimation

Gets or sets the PopupAnimation for the opening and closing of the associated popup.

public PopupAnimation PopupAnimation { get; set; }

Property Value

PopupAnimation:

The PopupAnimation for the opening and closing of the associated popup.

PopupBackground

Gets or sets the Brush for the popup's background.

public Brush PopupBackground { get; set; }

Property Value

Brush:

The Brush for the popup's background.

Remarks

This property is only used when PopupContent is specified.

PopupBorderBrush

Gets or sets the Brush for the popup's border.

public Brush PopupBorderBrush { get; set; }

Property Value

Brush:

The Brush for the popup's border.

Remarks

This property is only used when PopupContent is specified.

PopupBorderThickness

Gets or sets the Thickness for the popup's border.

public Thickness PopupBorderThickness { get; set; }

Property Value

Thickness:

The Thickness for the popup's border.

Remarks

This property is only used when PopupContent is specified.

PopupContent

Gets or sets the content that is displayed on the button's Popup.

public object PopupContent { get; set; }

Property Value

Object:

The content that is displayed on the button's Popup.

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

Gets or sets the DataTemplate to use for the PopupContent.

public DataTemplate PopupContentTemplate { get; set; }

Property Value

DataTemplate:

The DataTemplate to use for the PopupContent.

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

Gets or sets the DataTemplateSelector to use for the PopupContent.

public DataTemplateSelector PopupContentTemplateSelector { get; set; }

Property Value

DataTemplateSelector:

The DataTemplateSelector to use for the PopupContent.

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

Gets or sets the CornerRadius for the popup's border.

public CornerRadius PopupCornerRadius { get; set; }

Property Value

CornerRadius:

The CornerRadius for the popup's border.

Remarks

This property is only used when PopupContent is specified.

PopupHorizontalOffset

Gets or sets the horizontal distance between the target origin and the popup alignment point.

public double PopupHorizontalOffset { get; set; }

Property Value

Double:

The horizontal distance between the target origin and the popup alignment point. The default value is 0.

PopupIndicator

Gets or sets the object used in the indicator portion of the PopupButton.

public UIElement PopupIndicator { get; set; }

Property Value

UIElement:

The object used in the indicator portion.

PopupIndicatorTemplate

Gets or sets the DataTemplate used to present the indicator portion of the PopupButton.

public DataTemplate PopupIndicatorTemplate { get; set; }

Property Value

DataTemplate:

The DataTemplate used to present the indicator portion.

PopupIndicatorToolTip

Gets or sets the tool-tip object that is displayed for the popup indicator element.

[Localizability(LocalizationCategory.ToolTip)]
public object PopupIndicatorToolTip { get; set; }

Property Value

Object:

The tool-tip object that is displayed for the popup indicator element.

PopupMenu

Gets or sets the ContextMenu that is opened by the PopupButton.

public ContextMenu PopupMenu { get; set; }

Property Value

ContextMenu:

The ContextMenu that is opened by the PopupButton.

Remarks

This property takes precedence over the PopupContent-related properties. Therefore, if this property is set, the PopupContent-related properties are ignored.

PopupMenuDataContext

Gets or sets the the data context for the PopupMenu when it participates in data binding.

public object PopupMenuDataContext { get; set; }

Property Value

Object:

The object to use as the PopupMenu data context. 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

Gets or sets the Thickness of the popup's padding.

public Thickness PopupPadding { get; set; }

Property Value

Thickness:

The Thickness of the popup's padding.

Remarks

This property is only used when PopupContent is specified.

PopupPlacement

Gets or sets a PlacementMode indicating where the popup appears relative to the button.

public PlacementMode PopupPlacement { get; set; }

Property Value

PlacementMode:

A PlacementMode indicating where the popup appears relative to the button. The default value is Bottom.

PopupVerticalOffset

Gets or sets the vertical distance between the target origin and the popup alignment point.

public double PopupVerticalOffset { get; set; }

Property Value

Double:

The vertical distance between the target origin and the popup alignment point. The default value is 0.

StaysOpen

Gets or sets a value that indicates whether the Popup closes when the control is no longer in focus.

public bool StaysOpen { get; set; }

Property Value

Boolean:

true if the Popup closes when the control is no longer in focus; otherwise, false. The default is false.

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

Boolean:

true if 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()

Invoked whenever application code or internal processes call ApplyTemplate.

public override void OnApplyTemplate()

OnClick()

Called the button is clicked.

protected override void OnClick()

OnCreateAutomationPeer()

Returns an AutomationPeer object for this control instance.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer:

An AutomationPeer instance.

OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs)

Occurs when the property value has changed.

protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
Parameter Type Description
e DependencyPropertyChangedEventArgs

The DependencyPropertyChangedEventArgs containing data related to this event.

OnKeyDown(KeyEventArgs)

Occurs when a key is pressed.

protected override void OnKeyDown(KeyEventArgs e)
Parameter Type Description
e KeyEventArgs

The KeyEventArgs instance containing the event data.

OnKeyUp(KeyEventArgs)

Occurs when a key is released.

protected override void OnKeyUp(KeyEventArgs e)
Parameter Type Description
e KeyEventArgs

The KeyEventArgs instance containing the event data.

OnMouseLeftButtonDown(MouseButtonEventArgs)

Occurs when the left mouse button is pressed.

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
Parameter Type Description
e MouseButtonEventArgs

The MouseButtonEventArgs instance containing the event data.

OnMouseLeftButtonUp(MouseButtonEventArgs)

Occurs when the left mouse button is released.

protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
Parameter Type Description
e MouseButtonEventArgs

The MouseButtonEventArgs instance containing the event data.

OnMouseWheel(MouseWheelEventArgs)

Occurs when the mouse wheel is rotated.

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 RoutedEventArgs that contains the event data.

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 RoutedEventArgs that contains the event data.

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 CancelRoutedEventArgs that contains the event data.

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.

public event RoutedEventHandler PopupClosed

Event Type

RoutedEventHandler

PopupOpened

Occurs when the IsPopupOpen property changes to true.

public event RoutedEventHandler PopupOpened

Event Type

RoutedEventHandler

PopupOpening

Occurs before the IsPopupOpen property changes to true.

public event EventHandler<CancelRoutedEventArgs> PopupOpening

Event Type

EventHandler<CancelRoutedEventArgs>

Explicit Interface Implementations

IPopupAnchor.IsKeyboardFocusWithinPopup

Gets whether keyboard focus is within the child popup.

bool IPopupAnchor.IsKeyboardFocusWithinPopup { get; }

Returns

Boolean:

true if keyboard focus is within the child popup; otherwise, false.

IPopupAnchor.PopupChild

Gets the child element within the popup.

UIElement IPopupAnchor.PopupChild { get; }

Returns

UIElement:

The child element within the popup.

IPopupAnchor.PopupStaysOpen

Gets whether the popup stays open, even when the popup loses focus, until explicitly closed.

bool IPopupAnchor.PopupStaysOpen { get; }

Returns

Boolean:

true if the popup stays open, even when the popup loses focus, until explicitly closed.

IPopupAnchor.SupportsAltDownToOpen

Gets whether the element supports pressing Alt+Down to open the popup.

bool IPopupAnchor.SupportsAltDownToOpen { get; }

Returns

Boolean:

true if the element supports pressing Alt+Down to open the popup; otherwise, false.

IPopupAnchor.WasPopupOpenedWithKeyboard

Gets or sets whether the child popup was opened via the keyboard.

bool IPopupAnchor.WasPopupOpenedWithKeyboard { get; set; }

Returns

Boolean:

true if the child popup was opened via the keyboard; otherwise, false.

Fields

CornerRadiusProperty

Identifies the CornerRadius dependency property. This field is read-only.

public static readonly DependencyProperty CornerRadiusProperty

DisplayModeProperty

Identifies the DisplayMode dependency property. This field is read-only.

public static readonly DependencyProperty DisplayModeProperty

HasDropShadowProperty

Identifies the HasDropShadow dependency property. This field is read-only.

public static readonly DependencyProperty HasDropShadowProperty

IsAutoFocusOnOpenEnabledProperty

Identifies the IsAutoFocusOnOpenEnabled dependency property. This field is read-only.

public static readonly DependencyProperty IsAutoFocusOnOpenEnabledProperty

IsPopupOpenProperty

Identifies the IsPopupOpen dependency property. This field is read-only.

public static readonly DependencyProperty IsPopupOpenProperty

IsTransparencyModeEnabledProperty

Identifies the IsTransparencyModeEnabled dependency property. This field is read-only.

public static readonly DependencyProperty IsTransparencyModeEnabledProperty

PopupAllowsTransparencyProperty

Identifies the PopupAllowsTransparency dependency property. This field is read-only.

public static readonly DependencyProperty PopupAllowsTransparencyProperty

PopupAnimationProperty

Identifies the PopupAnimation dependency property. This field is read-only.

public static readonly DependencyProperty PopupAnimationProperty

PopupBackgroundProperty

Identifies the PopupBackground dependency property. This field is read-only.

public static readonly DependencyProperty PopupBackgroundProperty

PopupBorderBrushProperty

Identifies the PopupBorderBrush dependency property. This field is read-only.

public static readonly DependencyProperty PopupBorderBrushProperty

PopupBorderThicknessProperty

Identifies the PopupBorderThickness dependency property. This field is read-only.

public static readonly DependencyProperty PopupBorderThicknessProperty

PopupClosedEvent

Identifies the PopupClosed routed event. This field is read-only.

public static readonly RoutedEvent PopupClosedEvent

PopupContentProperty

Identifies the PopupContent dependency property. This field is read-only.

public static readonly DependencyProperty PopupContentProperty

PopupContentTemplateProperty

Identifies the PopupContentTemplate dependency property. This field is read-only.

public static readonly DependencyProperty PopupContentTemplateProperty

PopupContentTemplateSelectorProperty

Identifies the PopupContentTemplateSelector dependency property. This field is read-only.

public static readonly DependencyProperty PopupContentTemplateSelectorProperty

PopupCornerRadiusProperty

Identifies the PopupCornerRadius dependency property. This field is read-only.

public static readonly DependencyProperty PopupCornerRadiusProperty

PopupHorizontalOffsetProperty

Identifies the PopupHorizontalOffset dependency property. This field is read-only.

public static readonly DependencyProperty PopupHorizontalOffsetProperty

PopupIndicatorProperty

Identifies the PopupIndicator dependency property. This field is read-only.

public static readonly DependencyProperty PopupIndicatorProperty

PopupIndicatorTemplateProperty

Identifies the PopupIndicatorTemplate dependency property. This field is read-only.

public static readonly DependencyProperty PopupIndicatorTemplateProperty

PopupIndicatorToolTipProperty

Identifies the PopupIndicatorToolTip dependency property. This field is read-only.

public static readonly DependencyProperty PopupIndicatorToolTipProperty

PopupMenuDataContextProperty

Identifies the PopupMenuDataContext dependency property. This field is read-only.

public static readonly DependencyProperty PopupMenuDataContextProperty

PopupMenuProperty

Identifies the PopupMenu dependency property. This field is read-only.

public static readonly DependencyProperty PopupMenuProperty

PopupOpenedEvent

Identifies the PopupOpened routed event. This field is read-only.

public static readonly RoutedEvent PopupOpenedEvent

PopupOpeningEvent

Identifies the PopupOpening routed event. This field is read-only.

public static readonly RoutedEvent PopupOpeningEvent

PopupPaddingProperty

Identifies the PopupPadding dependency property. This field is read-only.

public static readonly DependencyProperty PopupPaddingProperty

PopupPlacementProperty

Identifies the PopupPlacement dependency property. This field is read-only.

public static readonly DependencyProperty PopupPlacementProperty

PopupVerticalOffsetProperty

Identifies the PopupVerticalOffset dependency property. This field is read-only.

public static readonly DependencyProperty PopupVerticalOffsetProperty

StaysOpenProperty

Identifies the StaysOpen dependency property. This field is read-only.

public static readonly DependencyProperty StaysOpenProperty

Inherited Members

Extension Methods