New to Telerik UI for WPF? Download free 30-day trial

Prevent the Closing of Panes in the Auto-Hide Area When ContextMenu is Opened

Environment

Product Version 2019.3.917
Product RadDocking for WPF

Description

In the following solution we are going to demonstrates how to prevent RadPanes from closing in the auto-hide area when a ContextMenu is opened.

Solution

To achieve this requirement you can handle the ContextMenuOpening event of the element to which you've added the ContextMenu (the TextBlock in this case) and focus its content.

Example 1: Subscribe to the ContextMenuOpening event

    private void TextBlock_ContextMenuOpening(object sender, ContextMenuEventArgs e) 
    { 
        var element = sender as FrameworkElement; 
        element.Focus(); 
    } 
Please note that in the case of the TextBlock you also need to set its Focusable property to True.

Example 2: Set Focusable to True

    <TextBlock Focusable="True" Text="Open the Context menu with right klick" ContextMenuOpening="TextBlock_ContextMenuOpening"> 
        <TextBlock.ContextMenu> 
            <ContextMenu> 
                <MenuItem Header="MenuItem1" /> 
                <MenuItem Header="MenuItem2" /> 
            </ContextMenu> 
        </TextBlock.ContextMenu> 
    </TextBlock> 
In this article
Not finding the help you need? Improve this article