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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:14:39+00:00 2026-05-13T09:14:39+00:00

I have Menu in my app. I’m visualizing it using hierarchical data template: <MenuItem

  • 0

I have Menu in my app. I’m visualizing it using hierarchical data template:

    <MenuItem Header="Main menu" ItemsSource="{Binding ApplicationMenu}" >
        <MenuItem.ItemTemplate>                    
            <HierarchicalDataTemplate DataType="{x:Type tm:RMenuItem}" 
                                      ItemsSource="{Binding Path=ChildrenItems}">                        
                <MenuItem Header="{Binding Name}" Command="{Binding RunOperationCommand}" />
            </HierarchicalDataTemplate>
        </MenuItem.ItemTemplate>
    </MenuItem>

menu looks like as it should, but Command for each menu item is not fired! Even more – it is not bounded, which could be seen in debugger: get accessor of ICommand Property has been never executed.
Why it happens so?

Doing as usual works perfect:

<Menu>
    <MenuItem Header="SomeHeader" Command="{Binding RunOperationCommand}"/>
<Menu>
  • 1 1 Answer
  • 3 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-13T09:14:39+00:00Added an answer on May 13, 2026 at 9:14 am

    The difference between the first and the second example in your question is that in the second code snippet you are binding MenuItem.Command to the parent’s data context, which has the RunOperationCommand defined. Whereas in the first example with the HierarchicalDataTemplate you are binding to the “local” DataContext, which is a menu item. It doesn’t have the appropriate property, so the binding fails.

    You have several options:

    • one is to extend your menu items with the command property, like you did in your answer already;
    • bind to the relative source up in the visual tree, which has the data context with the command, e.g. assuming that the command is in your window’s DataContext:

        <MenuItem Header="Main menu" ItemsSource="{Binding ApplicationMenu}" >
            <MenuItem.ItemTemplate>                    
                <HierarchicalDataTemplate DataType="{x:Type tm:RMenuItem}" 
                                          ItemsSource="{Binding Path=ChildrenItems}">                        
                    <MenuItem Header="{Binding Name}" 
                              Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RunOperationCommand}" 
                    />
                </HierarchicalDataTemplate>
            </MenuItem.ItemTemplate>
        </MenuItem>
    

    • Make a StaticResource from your command, similar to this blog post approach

    <Window.Resources>
         <coreView:CommandReference x:Key="RunOperationCommand"
                                    Command="{Binding RunOperationCommand}" />
    </Window.Resources>
    
        <MenuItem Header="Main menu" ItemsSource="{Binding ApplicationMenu}" >
            <MenuItem.ItemTemplate>                    
                <HierarchicalDataTemplate DataType="{x:Type tm:RMenuItem}" 
                                          ItemsSource="{Binding Path=ChildrenItems}">                        
                    <MenuItem Header="{Binding Name}" 
                              Command="{StaticResource RunOperationCommand}" 
                    />
                </HierarchicalDataTemplate>
            </MenuItem.ItemTemplate>
        </MenuItem>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that so far consists of two Activities: The Main Menu
In my app's main menu I have a menu item that I'd like to
I have main menu in my app supporting only landscape mode. I implement landscape
I have styled my Menu/ContextMenu/MenuItem controls in App.xaml so that those styles apply to
I have preference menu in my app. I am using Android 1.6. I wanted
I have a menu item inside the main app menu and I’d like to
I am building a small app using wxPython.I have created a menu bar ,
I have a menu in my app android. When I click on add favorites,
I have an iPad app which has a funky Path-style menu which is present
I have this need to place my app in the share/send context menu so

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.