Creating a flexible Context Menu

I would like to have a context menu which I can setup and open from basically anywhere in my C# code, so it should not be bound to a 'context' like a button or textbox.

My first idea was to use a window and apply a similar behaviour to it, like when clicking on the main window it closes. Would that be an option?

I've only found samples like this, where it's bound to a text box.
<TextBox Text="Text" Margin="25">
      <TextBox.ContextMenu>
            <ContextMenu>
                  <MenuItem x:Name="MenuItem1">Menu Entry</MenuItem>
          </ContextMenu>
    </TextBox.ContextMenu>
</TextBox>
FlorianStruckAsked:
Who is Participating?
 
Dennis AriesConnect With a Mentor CEO @ Arkro ITCommented:
You will have to create the contextmenu as a resource. http://www.c-sharpcorner.com/Resources/Detail.aspx?ResourceId=651 has good example of that.
0
 
FlorianStruckAuthor Commented:
Thanks. You did point me into the right direction.

To create, setup and open a ContextMenu in C# Code some information can be found here.
http://evgenya.wordpress.com/2008/04/14/wpf-building-contextmenu-on-fly
0
 
Dennis AriesCEO @ Arkro ITCommented:
Glad to be of help.
 
0
All Courses

From novice to tech pro — start learning today.