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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:47:00+00:00 2026-05-25T11:47:00+00:00

I have a HierarchicalDataTemplate which has some simple Items contained in a horizontal StackPanel.

  • 0

I have a HierarchicalDataTemplate which has some simple Items contained in a horizontal StackPanel.
A context menu is assigned to the root StackPanel container as well:

<HierarchicalDataTemplate DataType="{x:Type data:GroupViewModel}"
                              ItemsSource="{Binding Path=Children}">
    <StackPanel Orientation="Horizontal" Margin="2" ContextMenuOpening="groupContextMenuOpening">
        <StackPanel.ContextMenu>
            <StaticResource ResourceKey="groupContextMenu" />
        </StackPanel.ContextMenu>

        <Rectangle Width="16" Height="15" Fill="{Binding Converter={StaticResource HierarchyLevelConverter}}" Margin="0 0 3 0" Cursor="Hand" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseLeftButtonDown" >
                    <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding SetCurrent}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>                
        </Rectangle>
        <Image Width="16" Height="15" Source="{Binding Path=GroupState, Converter={StaticResource GroupStateConverter}}" Cursor="Hand" Margin="0 0 3 0">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseLeftButtonDown" >
                    <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding ToggleGroupState}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Image>
    </StackPanel>
</HierarchicalDataTemplate>

The host TreeView also uses a ContextMenu.
The idea is that if you right click on an item in the TreeView, you will get it’s ContextMenu.
If you right clik in empty space in the tree view you will get the ‘default’ context menu with lesser options.

This is all working expcept one odd problem.
As you can see the horizontal StackPanel leaves a margin between the images. If I right click in that space between items, the TreeView context menu shows up. I would expect the ContextMenu defined in my HierarchicalDataTemplate to pop up as i AM right click on the StackPanel itself.

I’ve found that if I assign a background color to the StackPanel it then works, but I would prefer to avoid this if possible.

Any ideas?

  • 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-25T11:47:01+00:00Added an answer on May 25, 2026 at 11:47 am

    Set the Background of the StackPanel to Transparent to make it hit test in those empty areas.

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

Sidebar

Related Questions

I have a TreeView which contains items populated by a HierarchicalDataTemplate. I am trying
I have a template for treeView item: <HierarchicalDataTemplate x:Key=RatesTemplate> <StackPanel Orientation=Horizontal> <TextBlock Text={Binding Path=ID}/>
I've got something: <HierarchicalDataTemplate DataType={x:Type MyService:Country} ItemsSource={Binding Path=ListOfAreas}> <StackPanel Orientation=Horizontal> <TextBlock TextAlignment=Center Text={Binding Path=Name}/>
I have a TreeView which uses a HierarchicalDataTemplate to bind its data. It looks
I have a tree view defined as follows: <HierarchicalDataTemplate x:Key=ChildTemplate ItemsSource={Binding Children}> <TextBlock Text={Binding
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have TreeViewItem s where the HierarchicalDataTemplate consists of a Grid with 3 columns
I have a WPF TreeView with 2 levels of data and 2 HierarchicalDataTemplate to
I have Menu in my app. I'm visualizing it using hierarchical data template: <MenuItem
I have TextBlock inside HierarchicalDataTemplate. I need to set foreground color to Red when

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.