Adblock breaks this site

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

Discussion in 'Programming General' started by hampe-92, Nov 16, 2008.

  1. hampe-92

    hampe-92 Forum Addict

    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0
    WPF in Expression Blend -add context menu item click-event

    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
     
  2. Flaming Idiots

    Flaming Idiots Active Member
    Visual Basic Programmers

    Joined:
    Dec 22, 2005
    Posts:
    235
    Referrals:
    1
    Sythe Gold:
    0
    Two Factor Authentication User
    WPF in Expression Blend -add context menu item click-event

    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>
     
  3. hampe-92

    hampe-92 Forum Addict

    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0
    WPF in Expression Blend -add context menu item click-event

    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 :)
     
  4. Flaming Idiots

    Flaming Idiots Active Member
    Visual Basic Programmers

    Joined:
    Dec 22, 2005
    Posts:
    235
    Referrals:
    1
    Sythe Gold:
    0
    Two Factor Authentication User
    WPF in Expression Blend -add context menu item click-event

    Yeah, just set the Name property of each one.
     
  5. hampe-92

    hampe-92 Forum Addict

    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0
    WPF in Expression Blend -add context menu item click-event

    yeah of course... just one problem tho, I can't find any Name property in the menu...:confused:

    EDIT: ah, nvm.. it's just to change it in the xaml.. thx :)
     
< VB6 on Vista (laaag) | Python 2.6 (Saving Scripts) >


 
 
Adblock breaks this site