ContextMenu does not appear when clicking on "empty space" in the StackPanel

I have a HierarchicalDataTemplate that contains some simple elements contained in a horizontal StackPanel. The context menu is also assigned to the StackPanel root container:

<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 TreeView tree also uses ContextMenu. The idea is that if you right-click on an item in a TreeView, you will get ContextMenu. If you are right clik in the empty space in the tree view, you will get a default context menu with smaller options.

, . , StackPanel . , TreeView. , ContextMenu, HierarchicalDataTemplate, , StackPanel.

, StackPanel, , , .

?

+5
1

Background StackPanel Transparent, .

+16

All Articles