How to Customize or Remove 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 RadPane's Menu

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

  1. You can create a custom class CustomRadDockingCommands. Inside you can create a singleton property of type Telerik.Windows.Controls.RoutedUICommand. Example 1 demonstrates how you can do that.

    Example 1: Create Singleton command property

        public class CustomRadDockingCommands 
        { 
            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's RadContextMenu and RadMenuItem controls. You can use either the built-in RadDockingCommands or create a custom one - both approaches are demonstrated in this topic. Set the created DataTemplate to RadPane's ContextMenuTemplate property. Example 2 show how to set RadPane's ContextMenuTemplate property.

    Example 2: Custom DataTemplate for the ContextMenuTemplate property

        <Window.Resources> 
            <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> 
        </Window.Resources> 
        <Grid> 
            <telerik:RadDocking x:Name="radDocking"> 
                <telerik:RadSplitContainer> 
                    <telerik:RadPaneGroup> 
                        <telerik:RadPane Title="Pane 1" Content="Pane 1 Content" /> 
                        <telerik:RadPane Title="Pane 2" Content="Pane 2 Content" /> 
                        <telerik:RadPane Title="Pane 3" Content="Pane 3 Content" /> 
                        <telerik:RadPane Title="Pane 4" Content="Pane 4 Content" /> 
                    </telerik:RadPaneGroup> 
                </telerik:RadSplitContainer> 
            </telerik:RadDocking> 
        </Grid> 
    
  3. You should implement your custom logic in the OnCloseAllPanesButThis and OnCloseAllPanesButThisCanExecute methods. They specify whether the command can be executed and what action is performed, when it is executed. Example 3 demonstrate sample logic for the command methods.

    Example 3: Implement Execute and CanExecute methods

        public static class RadDockingCommands 
        { 
            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; 
                    } 
                } 
            } 
     
            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 in the CustomRadDockingCommands constructor class. Example 4 shows the final structure of the CustomRadDockingCommands class.

    Example 4: Register CloseAllPanesButThisCommand custom command

        public class CustomRadDockingCommands 
        { 
            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; 
                } 
            } 
     
            static CustomRadDockingCommands() 
            { 
                CommandManager.RegisterClassCommandBinding(typeof(RadPaneGroup), new CommandBinding(CustomRadDockingCommands.CloseAllPanesButThisCommand, OnCloseAllPanesButThis, OnCloseAllPanesButThisCanExecute)); 
            } 
     
            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; 
                    } 
                } 
            } 
        } 
    
    Run your demo. The RadPane's menu should look like the snapshot below.

Customize or Remove the RadPane's Menu

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).

Example 5: Set ContextMenuTemplate property to null

<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

In this article
Not finding the help you need? Improve this article