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 9204873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:48:56+00:00 2026-06-17T23:48:56+00:00

I have inherited a WPF application developed against an older version of Prism (Composite

  • 0

I have inherited a WPF application developed against an older version of Prism (Composite Application Guidance 1.0). The general pattern in this app is to use Microsoft.Practices.Composite.Wpf.DelegateCommand in the ViewModel and avoids code-behind event handlers. It uses an MVP pattern in which the Presenter represents the ViewModel to which the XAML is bound.

I have a DataGrid with a ContextMenu and the XAML binding looks as follows:

<DataGrid.ContextMenu>
    <ContextMenu>
        <MenuItem Header="Do Stuff" Command="{Binding DoStuffCommand.Command}" />
    </ContextMenu>
</DataGrid.ContextMenu>

DoStuffCommand is actually a custom CommandBase object, which is exposed as a property on the Presenter. DoStuffCommand.Command is the actual DelegateCommand object. The DelagateCommand is constructed with Execute and CanExecute methods as defined in the Presenter (this.DoStuff, this.DoStuffCanExecute).

On the first right-click CanExecute is called but on any subsequent clicks it is not. Furthermore there are other commands on the page that subsequently call DoStuffCommand.Command.RaiseCanExecuteChanged. When that happens the CanExecute method is actually called TWICE.

The original developer solved it by wiring up a right-click event on the datagrid and explicity calling RaiseCanExecuteChanged. The problem with that solution is that CanExecute runs TWICE every time. I have simplified the code for this post but in actuality there six different commands in that context menu, all firing twice with every event, and it’s causing performance problems and other glitches.

I would like to solve this properly so that the events fire once when the ContextMenu is opened and that’s it. It feels as though maybe multiple event handlers are getting attached and the solution lies in somewhere in this post, which I have studied at length. WPF ViewModel Commands CanExecute issue

These solutions seem to lie deep in the Prism libraries and I’m not sure exactly how to lay it properly into my solution. I would like to avoid touching or updating our Prism libraries if possible.

  • 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-17T23:48:58+00:00Added an answer on June 17, 2026 at 11:48 pm

    The answer did not lie in the Prism library or the Command framework at all. The ContextMenu was actually being declared twice in the XAML. The first one was attached to the DataGrid as I showed above. Another one was actually defined as a resource much earlier in the file and referenced by individual controls in the custom template columns.

    Sigh…If any other inexperienced WPF developers out there experience similar issues I can only suggest a thorough examination of your XAML controls before anything else.

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

Sidebar

Related Questions

I am developing a WPF application using the MVVM design pattern. I have a
We have inherited an application (Java-based, running on WebLogic 10.3.5) that makes extensive use
I have inherited couple of .Net (C#) application which does not have any tracing
I currently try to create classes for a paint-like WPF application. I have to
I am currently developing a new WPF application and have the majority of my
I maintain a large WPF application which I inherited from another developer. I use
So I have several comboboxes in my WPF application that don't change the selection
I'm writing tests using WiPFlash for a WPF application that has been developed in
I've inherited a rather large WPF application, and I need to generate application traces
I have a mixed Winform/WPF application which frequently throws the exception: Could not load

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.