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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:17:22+00:00 2026-05-12T05:17:22+00:00

I a have 2 distinct UI elements in distinct files : a menuItem (in

  • 0

I a have 2 distinct UI elements in distinct files : a menuItem (in window.xaml) and a userControl (in foo.xaml).

Both have exactly the same logic : they are enabled only if a condition is matched and call the same method. To code this logic, i use RoutedCommands.

I could use 2 different RoutedCommands in each file with same condition in the CanExecute and Executed. It works.

I would like to improve the code to follow the D.R.Y. rule and externalize the routedCommand and the attached methods. This is the binding in both files :

<CommandBinding Command="{x:Static RoutedCommands:TestRoutedCommand.test}"
                    Executed="RoutedCommands:TestRoutedCommand.OnTest"
                    CanExecute="RoutedCommands:TestRoutedCommand.CanTest" />

this is TestRoutedCmmand.cs :

public class TestRoutedCommand
{
    public static RoutedCommand test = new RoutedCommand();

    public static void OnTest(object sender, ExecutedRoutedEventArgs e)
    {
        System.Windows.MessageBox.Show("test -on");
    }

    public static void CanTest(object sender, CanExecuteRoutedEventArgs e)
    {
        System.Windows.MessageBox.Show("test -can");

        e.CanExecute = true;
    }
}

When I do that, the compiler report this error :

Error   1   unknown generation error, 'MC6005 :        
Executed="RoutedCommands:TestRoutedCommand.OnTest" is not valid.  
'RoutedCommands:TestRoutedCommand.OnTest' is not a valid name for an event handler method. 
Only instance methods of the generated class or code-behind are valid

(The translation may not be exact because the original message was not in English)

It seems that external methods are not supported, but i would be sure i did not miss something. I wonder if it is the fact that my methods are static ?

Is there another way to externalize my methods or do i have to stay with these 4 methods calling only 2 others ?

Note : in my project this is more 30 duplicated routedCommand methods callings only 2 others… this is why it bother me so much.

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-05-12T05:17:23+00:00Added an answer on May 12, 2026 at 5:17 am

    I answer myself :

    As the compiler does not accept extern delegates with RoutedCommand, the best practice is to use a custom implementation of ICommand like these. No more CommandBinding is required and the problem is solved!

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

Sidebar

Related Questions

I am dynamically appending form elements. The newly appended elements need to have distinct
I have a random ordered array of 30 elements with only 3 distinct keys
If we have an (arbitrary) connected undirected graph G, whose edges have distinct weights,
I have two distinct (no inheritance) interfaces: IInvestable and IPricable and two classes: IndexClass
I have two distinct scenarios. One, where there is a many to many case,
Say I have y distinct values and I want to select x of them
I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO
I have the following query: SELECT DISTINCT w.name, count(*) FROM widgets AS w JOIN
I have a query: insert into #tmpRcIzm select distinct v.id_art, 'Y' from openxml(@hDoc, '/art_komp/nol')
I have this SQL query: SELECT DISTINCT tb.SERIAL_NUM, tb.REVISION_NUM, tb.JOB_NUM, tb.JOB_TOTAL, tb.TEST_PROC, tb.BOX_NUM, tb.TEST_BENCH,

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.