Back to Devexpress

BarManager.DXContextMenu Attached Property

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

latest5.8 KB
Original Source

BarManager.DXContextMenu Attached Property

Gets or sets a context menu/popup control for a specific UI object. This is an attached property.

Namespace : DevExpress.Xpf.Bars

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

NuGet Package : DevExpress.Wpf.Core

Declaration

See GetDXContextMenu(UIElement) and SetDXContextMenu(UIElement, IPopupControl).

Returns

TypeDescription
DevExpress.Xpf.Bars.IPopupControl

An IPopupControl object that represents a context menu/popup control for a specific UI element.

|

Remarks

You can use the DXContextMenu attached property to associate a context menu/popup control with UI objects. The following objects are accepted by the DXContextMenu property:

To manually invoke a context menu associated with a specific UIElement, use the BarPopupBase.ShowElementContextMenu method.

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

See Also

PopupMenu

PopupMenuInfo

PopupControlContainer

ShowElementContextMenu(Object)

BarManager Class

BarManager Members

DevExpress.Xpf.Bars Namespace