• Log in or sign up for an account here: https://www.sythe.org/login

WPF in Expression Blend -add context menu item click-event

hampe-92

Forum Addict
Joined
Jul 10, 2008
Sythe Gold
0
Messages
328
In WPF in Blend there is no context menu control as in windows forms... so if I got it right, you have to go to properties for the window and scroll down to "Context menu". There are several of options for the menu but after some searching I found the "Items (Collection)" button...

then I added all my menu items that I needed, but I can't find how to hook them up to a click-event, (as you can do with regular controls by going to properties and then events)... I just CAN'T find any option like it:confused:

any ideas??
thx in advance
 
Two Factor Authentication User
In the XAML try setting the click handler normally. Just set the Click property to the name of the method that handles the click.

It should look something like this:

XAML
Code:
<FrameworkElement.ContextMenu>
  <ContextMenu>
    <MenuItem Header="Cut" Click="OnCut" />
    <MenuItem Header="Copy" Click="OnCopy" />
    <MenuItem Header="Paste" Click="OnPaste" />
  </ContextMenu>
</FrameworkElement.ContextMenu>
 
In the XAML try setting the click handler normally. Just set the Click property to the name of the method that handles the click.

It should look something like this:

XAML
Code:
<FrameworkElement.ContextMenu>
  <ContextMenu>
    <MenuItem Header="Cut" Click="OnCut" />
    <MenuItem Header="Copy" Click="OnCopy" />
    <MenuItem Header="Paste" Click="OnPaste" />
  </ContextMenu>
</FrameworkElement.ContextMenu>

Ah Thank you very much! :)
That's a lot easier than that fucked up blend menu :p

EDIT: one more thing, is it possible to name the context menu items?
cause I have to chech if one specific menu item is checked or not... thx :)
 
Runescape Gamblingrunescape gambling
Back
Top