Edit this page

How to Customize or Remove the RadPane's Menu

The purpose of this tutorial is to show you how to customize the RadPane menu.

For more information about the RadPane structure, read here or read this one if you want to learn more about the RadPane's menu.

Customizing the RadPane's Menu

In order to add custom commands to the RadPane's menu, you should perform the following steps:

  1. Create a singleton property of type Telerik.Windows.Controls.RoutedUICommand. In the following example the custom command is named CloseAllPanesButThis.

        public static class RadDockingCommands
        {
            private static RoutedUICommand closeAllPanesButThisCommand;
    
            public static RoutedUICommand CloseAllPanesButThisCommand
            {
                get
                {
                    if (closeAllPanesButThisCommand == null)
                    {
                        closeAllPanesButThisCommand = new RoutedUICommand("Close all panes but this", "CloseAllPanesButThisCommand", typeof(RadDockingCommands));
                    }
                    return closeAllPanesButThisCommand;
                }
            }
        }
    
  2. Create a custom DataTemplate by using the Telerik RadContextMenu and RadMenuItem controls. You can use either the built-in RadDockingCommands or create a custom one - the both approaches are demonstrated in this topic. Set the created DataTemplate to the RadPane's ContextMenuTemplate property. In the following code-snippet is shown how to set the RadPane's ContextMenuTemplate property.

        <DataTemplate x:Key="ContextMenuTemplate">
            <telerik:RadContextMenu InheritDataContext="False">
                <telerik:RadMenuItem 
                    IsChecked="{Binding IsFloatingOnly}"
                    Command="telerik:RadDockingCommands.Floating" 
                    CommandParameter="{Binding}"                
                    CommandTarget="{Binding}"
                    Header="{Binding Command.Text, RelativeSource={RelativeSource Self}}" />
    
                <telerik:RadMenuItem 
                    IsChecked="{Binding IsDockableOptionChecked}" 
                    Command="telerik:RadDockingCommands.Dockable" 
                    CommandParameter="{Binding}"
                    CommandTarget="{Binding}"
                    Header="{Binding Command.Text, RelativeSource={RelativeSource Self}}" />
    
                <telerik:RadMenuItem 
                    Command="telerik:RadDockingCommands.CloseAllPanesButThisCommand"
        CommandParameter="{Binding}" 
                    CommandTarget="{Binding}"
                    Header="{Binding Command.Text, RelativeSource={RelativeSource Self}}" />
            </telerik:RadContextMenu>
        </DataTemplate>
    
        <Style TargetType="telerik:RadPane">
            <Setter Property="ContextMenuTemplate" Value="{StaticResource ContextMenuTemplate}" />
        </Style>
    
  3. You should implement your custom logic in the OnCloseAllPanesButThis and OnCloseAllPanesButThisCanExecute event handlers. The following code-snippet representis a sample logic for the handlers.

        public static class RadDockingCommands
        {
            public static void OnCloseAllPanesButThis(object sender, ExecutedRoutedEventArgs e)
            {
                var pane = e.Parameter as RadPane;
                if (pane != null)
                {
                    var paneGroup = pane.PaneGroup;
                    if (paneGroup != null)
                    {
                        var panesToClose = paneGroup.EnumeratePanes().Where(x => !x.IsHidden && x.IsPinned);
                        foreach (var paneToClose in panesToClose)
                        {
                            if (paneToClose != pane)
                            {
                                paneToClose.IsHidden = true;
                            }
                        }
                    }
                }
            }
    
            public static void OnCloseAllPanesButThisCanExecute(object sender, CanExecuteRoutedEventArgs e)
            {
                e.CanExecute = false;
                var paneGroup = sender as RadPaneGroup;
                if (paneGroup != null)
                {
                    int childrenCount = paneGroup.EnumeratePanes().Count(x => !x.IsHidden && x.IsPinned);
    
                    if (childrenCount > 1)
                    {
                        e.CanExecute = true;
                    }
                    else
                    {
                        e.CanExecute = false;
                    }
                }
            }
        }
    
  4. Your menu command is ready and you have a custom DataTemplate, which is set to the ContextMenuTemplate property. The next step is to register your custom command by using the Telerik.Windows.Controls.CommandManager class. You can do that in the following manner:

        CommandManager.RegisterClassCommandBinding(
            typeof(RadPaneGroup),
             new CommandBinding(
                RadDockingCommands.CloseAllPanesButThisCommand,
                null,
                null));
    

Run your demo. The RadPane's menu should look like the snapshot below.

Removing the RadPane's Menu

In order to remove the RadPane's Menu, you should set the RadPane's ContextMenuTemplate property to null (respectively {x:Null} in XAML).

<telerik:RadDocking x:Name="radDocking">
    <telerik:RadDocking.DocumentHost>
        <telerik:RadSplitContainer>
            <telerik:RadPaneGroup>
                <telerik:RadPane x:Name="radPane"
                            Title="Pane 1"
                            ContextMenuTemplate="{x:Null}">
                    <TextBlock Text="Some simple text here" />
                </telerik:RadPane>
            </telerik:RadPaneGroup>
        </telerik:RadSplitContainer>
    </telerik:RadDocking.DocumentHost>
</telerik:RadDocking>

radPane.ContextMenuTemplate = null;
radPane.ContextMenuTemplate = Nothing

See Also