Back to Devexpress

PopupMenu Class

wpf-devexpress-dot-xpf-dot-bars.md

latest10.0 KB
Original Source

PopupMenu Class

A regular popup menu.

Namespace : DevExpress.Xpf.Bars

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public class PopupMenu :
    PopupMenuBase,
    ILinksHolder,
    IMultipleElementRegistratorSupport,
    IBarNameScopeSupport,
    IInputElement,
    ILogicalChildrenContainer
vb
Public Class PopupMenu
    Inherits PopupMenuBase
    Implements ILinksHolder,
               IMultipleElementRegistratorSupport,
               IBarNameScopeSupport,
               IInputElement,
               ILogicalChildrenContainer

The following members return PopupMenu objects:

Remarks

Use the PopupMenu class to create a popup menu. For instance, you can use it to represent a context menu for a control.

Important

If using a PopupMenu instance causes design time exceptions, use the PopupMenuInfo class instead.

To add elements (bar items and bar item links) to a menu, use the PopupMenu.Items collection.

A PopupMenu can be displayed as a drop-down control for a BarSplitButtonItem object. To associate a PopupMenu with the BarSplitButtonItem, assign it to the BarSplitButtonItem.PopupControl property.

Example

This example shows how to associate a popup menu with a TextBox control via the BarManager.DXContextMenu attached property.

The following image shows the result:

View Example

xaml
<Window
    x:Class="DXContextMenu_Ex.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
    Height="300" Width="300"
    Title="Window1">
    <Grid>
        <DockPanel>
            <TextBox
                x:Name="textEdit1"
                Width="200"
                Height="30"
                Text="right-click this textbox">
                <dxb:BarManager.DXContextMenu>
                    <dxb:PopupMenu>
                        <dxb:PopupMenu.Items>
                            <dxb:BarButtonItem
                                Content="Copy"
                                Glyph="pack://application:,,,/Images/copy16x16.png"
                                ItemClick="itemCopy_ItemClick" />
                            <dxb:BarButtonItem
                                Content="Paste"
                                Glyph="pack://application:,,,/Images/paste16x16.png"
                                ItemClick="itemPaste_ItemClick" />
                            <dxb:BarButtonItem
                                Content="Undo"
                                Glyph="pack://application:,,,/Images/undo16x16.png"
                                ItemClick="itemUndo_ItemClick" />
                            <dxb:BarButtonItem
                                Content="Redo"
                                Glyph="pack://application:,,,/Images/redo16x16.png"
                                ItemClick="itemRedo_ItemClick" />
                        </dxb:PopupMenu.Items>
                    </dxb:PopupMenu>
                </dxb:BarManager.DXContextMenu>
            </TextBox>
        </DockPanel>
    </Grid>
</Window>
csharp
using System.Windows;

namespace DXContextMenu_Ex {
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
        }

        private void itemCopy_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
            textEdit1.Copy();
        }

        private void itemPaste_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
            textEdit1.Paste();
        }

        private void itemUndo_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
            textEdit1.Undo();
        }

        private void itemRedo_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
            textEdit1.Redo();
        }
    }
}
vb
Imports System.Windows

Namespace DXContextMenu_Ex
    Partial Public Class Window1
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub itemCopy_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
            textEdit1.Copy()
        End Sub

        Private Sub itemPaste_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
            textEdit1.Paste()
        End Sub

        Private Sub itemUndo_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
            textEdit1.Undo()
        End Sub

        Private Sub itemRedo_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
            textEdit1.Redo()
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the PopupMenu class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-diagram-mdi/CS/MainWindow.xaml#L86

xml
<dxb:BarSplitButtonItem dxdiag:DiagramDesignerControl.BarItemName="{x:Static dxdiag:DefaultBarItemNames.PrintMenu}" Style="{StaticResource {dxdiagt:DiagramDesignerControlThemeKeys ResourceKey=PrintMenuStyle}}">
    <dxb:PopupMenu>
        <dxb:BarButtonItem dxdiag:DiagramDesignerControl.BarItemName="{x:Static dxdiag:DefaultBarItemNames.Print}" Style="{StaticResource {dxdiagt:DesignerControlCommandsThemeKeys ResourceKey=PrintCommandItemStyle}}" />

wpf-create-a-fluent-design-using-appearance-options/CS/FluentDesignTemplate/MainWindow.xaml#L59

xml
<dxb:BarSplitButtonItem Content="Alex" ActAsDropDown="True" BarItemDisplayMode="ContentAndGlyph" Glyph="{dx:DXImage SvgImages/Business Objects/BO_Customer.svg}">
    <dxb:PopupMenu>
        <dxb:BarButtonItem Content="Sign Out"/>

wpf-context-menu-create/CS/DXContextMenu_Ex/Window1.xaml#L16

xml
<dxb:BarManager.DXContextMenu>
    <dxb:PopupMenu>
        <dxb:PopupMenu.Items>

wpf-create-a-ribboncontrol/CS/RibbonControl_Ex/MainWindow.xaml#L150

xml
<dxb:BarSplitButtonItem.PopupControl >
    <dxb:PopupMenu>
        <dxb:BarButtonItem Name="bSave" Content="Save"

wpf-scheduler-create-reminders-in-code-and-implement-custom-reminder-window/CS/CustomReminderExample/CustomReminderWindow.xaml#L70

xml
<dxb:BarManager.DXContextMenu>
    <dxb:PopupMenu>
        <dxb:PopupMenu.Items>

Implements

ILinksHolder

Inheritance

Show 17 items

Object DispatcherObject DependencyObject Visual UIElement FrameworkElement Popup DevExpress.Xpf.Core.PopupBase BarPopupBase BarPopupExpandable PopupMenuBase PopupMenu RadialContextMenu

ApplicationMenu

GalleryDropDownPopupMenu

GridPopupMenu

PivotGridPopupMenu

See Also

PopupMenu Members

PopupMenuInfo

DevExpress.Xpf.Bars Namespace