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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:12:45+00:00 2026-05-14T01:12:45+00:00

Im deriving from a third party control. It is implementing ApplicationCommands.SelectAll. However the behaviour

  • 0

Im deriving from a third party control. It is implementing ApplicationCommands.SelectAll. However the behaviour i want is slightly different. there is no virtual method i can override, and when i register a class handler, like so

     CommandManager.RegisterClassCommandBinding(typeof(MyDerivedControl), new CommandBinding(ApplicationCommands.SelectAll, new ExecutedRoutedEventHandler(OnExecutedSelectAll), new CanExecuteRoutedEventHandler(OnCanExecuteSelectAll)));

My methods do not get called. The third party control i am deriving from is marking

e.Handled=true;

in its command handlers ( i know this cause i have seen the source, but i cant modify it )

What can i do?

  • 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-05-14T01:12:46+00:00Added an answer on May 14, 2026 at 1:12 am

    You have three options:

    1) You can register your CommandBinding to handle preview events instead of or in addition to regular events:

    CommandBinding cb = new CommandBinding(ApplicationCommands.SelectAll);
    cb.PreviewCanExecute += OnCanExecuteSelectAll;
    cb.PreviewExecuted += OnExecutedSelectAll;
    

    but beware – when registering handlers through CommandBinding if you have PreviewExecuted registered, the Executed handler will never run even if you explicitly set the e.Handled to false. It does work as expected for PreviewCanExecute/CanExecute pair of events though. This is the way CommandBinding class is implemented.
    So use PreviewExecuted only if you do not want the base class command handler to run.

    2) Alternatively you can register your command handlers through CommandManager directly:

    CommandManager.AddPreviewCanExecuteHandler(this, OnCanExecuteSelectAll);
    CommandManager.AddPreviewExecutedHandler(this, OnExecutedSelectAll);
    

    This is not a class handler though so you’d need to do it for each instance. Then in your handler you’d need to check weather this is the command you’re interested in (there is a reference to the command in event args). Note: you’ll still have to register CommandBinding, but if you’re going to only add handlers directly on CommandManager – you don’t need to register any handlers with that Command Binding.

    3) Or you can do a bit of a hack(not really a hack):

    this.AddHandler(CommandManager.CanExecuteEvent, new CanExecuteRoutedEventHandler(OnCanExecuteSelectAll), true);
    this.AddHandler(CommandManager.ExecutedEvent, new ExecutedRoutedEventHandler(OnExecutedSelectAll), true);
    

    this way you register command event handlers so that they will be executed even if they were already handled.
    As with the point above you’ll need to register command binding in order for the CommandManager events to be fired.
    This is almost the same stuff that is in the point 2 above, but when you call CommandManager.Add[one of the four events]Handler – the command manager calls AddHandler on the control using two argument version.

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

Sidebar

Related Questions

No related questions found

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.