Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8660473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:15:40+00:00 2026-06-12T16:15:40+00:00

In my WPF application I have a sort of node graph. I have added

  • 0

In my WPF application I have a sort of node graph. I have added a ContextMenu to these nodes, which appears when I right-click on stuff and so on.

The commands in the context menu come from a Service (Microsoft.Practices.ServiceLocation.ServiceLocator) with DelegateCommands, and those commands are updated with RaiseCanExecuteChanged(). The node that was right-clicked on is passed to this command service, which is used in the various CanExecute methods for the commands.

The nodes all have some properties which are used in these conditions, like whether it can be renamed or deleted, etc.

    private void ContextMenu_ContextMenuOpening(object sender, RoutedEventArgs e) {
        ServiceLocator.Current.GetInstance<IMenuCommandService>().ReloadICommandConditions();
    }

in IMenuCommandService:

    public void ReloadICommandConditions() {
        ((DelegateCommand<Node>) MyCommand).RaiseCanExecuteChanged();
    }

My ContextMenu (inside a DataTrigger & Setter):

<ContextMenu>
    <MenuItem Header="Rename"
              Command="{Binding MenuCommandService.Rename}"
              CommandParameter="{Binding Node}" />
    <MenuItem Header="Delete"
              Command="{Binding MenuCommandService.Delete}"
              CommandParameter="{Binding Node}" />
    ...
</ContextMenu>

My problem is that when I right click one of these nodes, the context menu that is displayed looks like it was configured for the previous node selected. Like if I right-click a deleteable node and then a non-deleteable node, the “Delete” command on the context menu will still be clickable. (If I then right-click the non-deleteable node, the context menu will then be correct and the “Delete” command is greyed out.)

So it looks like there’s some sort of delay from when the changes made after RaiseCanExecuteChanged() is actually there for the contextmenu to “pick up”. I could do a crude fix and only show the contextmenu after they have been updated (i.e. their CanExecute methods have been called), but I’d like to keep the two parts relatively separate.

Is there something obvious I’m missing, am I going about this in the wrong way, or does anyone have any other suggestions?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:15:41+00:00Added an answer on June 12, 2026 at 4:15 pm

    Sort-of-solved — I’m now manually passing the node that was right-clicked on to my MenuCommandService through that ReloadICommandConditions() method, and it’s holding a local reference to it, which it then uses instead of the parameter in its CanExecute() methods. Crude, but at least it works.

    I’ll keep this open for now in case anyone knows of a way that’s a bit more… elegant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my WPF application I have a Canvas in which I do some drawing.
I have a WPF application which connects to a remote database over internet and
I have a WPF application which tightly coupled to linq2sql through WCF. It now
In my WPF application, I have a host window which dynamically holds usercontrols at
I have a reasonably large application in C#/WPF made with MVVM (sort of). In
In WPF application I have MainWindow : Window which loads a POSView : UserControl
I have a WPF application in which I use entity framework with mysql connector/net
I am writing a small application to learn WPF/MVVM and I have sort of
In my WPF application I have a CheckBox whose IsChecked value is bound to
In my WPF application I have some drawing functionality. I have solved this using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.