Alex Aparin
Alex Aparin

Reputation: 4522

How to show ContextMenu in custom class?

I am learning wpf technology. I have created such custom class, which should react on mouse up event (should show popup menu)

public class CustomControl : UIElement
{
    protected override void OnMouseUp(MouseButtonEventArgs args)    
    {
         ContextMenu context_menu = new ContextMenu();
         // How to show context_menu at specific point?
    }
};

I don't know how to show created context menu at speficic position. It don't have specified Show method. UIElement don't have appropriated ContextMenu property

Edit: I am not using XAML (I don't want create dependency between source code and design)

Upvotes: 0

Views: 196

Answers (1)

Adwaenyth
Adwaenyth

Reputation: 2120

Using WPF you would design a context menu in XAML usually. A brief tutorial of how to do that is this for example.

Basically you write your context menu within the respective control and use Commands or mouse events like Click to assign a specific behaviour.

Upvotes: 1

Related Questions