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

  • Home
  • SEARCH
  • 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 8771521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:48:34+00:00 2026-06-13T17:48:34+00:00

I am trying to implement ICommandSource on a custom control (similar to a button).

  • 0

I am trying to implement ICommandSource on a custom control (similar to a button). Currently the implementation is mostly like it is displayed on the msdn page for ICommandSource and as it shows in the ButtonBase source code.

CanExecute fires on load of the control but doesn’t fire when any property has changed. The same command being passed to a regular button works just fine. When the property that is supposed to change changes, CanExecute fires and the button is enabled. The command is a Delegate Command.

I have tried CommandManager.InvalidateRequerySuggested(); but that has not worked.

Any ideas?

Here’s the implementation in the custom control:

private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    CollapsibleSplitButton csb = (CollapsibleSplitButton)d;
    csb.OnCommandChanged((ICommand)e.OldValue, (ICommand)e.NewValue);
}

private void OnCommandChanged(ICommand oldCommand, ICommand newCommand)
{
    if (oldCommand != null) UnhookCommand(oldCommand);
    if (newCommand != null) HookCommand(newCommand);
}

private void UnhookCommand(ICommand command)
{
    command.CanExecuteChanged -= OnCanExecuteChanged;
    UpdateCanExecute();
}

private void HookCommand(ICommand command)
{
    command.CanExecuteChanged += OnCanExecuteChanged;
    UpdateCanExecute();
}
private void OnCanExecuteChanged(object sender, EventArgs e)
{
    UpdateCanExecute();
}

private void UpdateCanExecute()
{
    if (Command != null)
        CanExecute = Command.CanExecute(CommandParameter);
    else
        CanExecute = true;
}

protected override bool IsEnabledCore
{
    get { return base.IsEnabledCore && CanExecute; }
}

Where I setup the Command I have:

...
    MyCommand = new DelegatingCommand(DoStuff, CanDoStuff);
...

private bool CanDoStuff()
{
    return (DueDate == null);
}

private void DoStuff() {//do stuff}
  • 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-13T17:48:35+00:00Added an answer on June 13, 2026 at 5:48 pm

    Managed to resolve the issue by wrapping the callback in an EventHandler.

    private EventHandler currentHandler;
    
    private void UnhookCommand(ICommand command)
    {
        if (currentHandler != null)
            command.CanExecuteChanged -= currentHandler;
        UpdateCanExecute();
    }
    
    private void HookCommand(ICommand command)
    {
        if (currentHandler == null) return;
    
        command.CanExecuteChanged += currentHandler;
        UpdateCanExecute();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying implement a custom login page to use in my JSF 2.0 application.
Trying to implement a search similar to here .This searches properties based on city,locality,property
Trying to implement a UITableView of names similar to the built-in Contacts iPhone app
I am trying implement a photo gallery similar to facebook in Android. I was
Ok well I'm trying implement something similar to the 'undo' function in many image
I've a webbrowser control and I'm trying implement IDocHostUIHandler in the container. However since
Trying to implement a similar approach towards our view counts for our web app.
I am trying implement drag and drop feature in RichTextBox (windows common control). It
I am currently trying implement a QThread that contains a socket connection. The socket
Trying to implement Ryan's JS implementation of the facebook login, via his Railscast: http://railscasts.com/episodes/360-facebook-authentication

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.