Bind Command to the HelpCommand property

The "Help" button of the RadRibbonView is not visible by default. To learn how to show it and change its icon, read the Show Help Button and Change its Image.

Bind Command to the HelpCommand property

The RadRibbonView exposes a property called HelpCommand which can be bound to an object of type ICommand. This command will be executed when the built-in help button is clicked.In this section we will demonstrate how to create a custom command and bind it to the HelpCommand property.

First, let’s define a RadRibbonView in our view and set the HelpButtonVisibility to True.

Example 1: Defining a RadRibbonView

<telerik:RadRibbonView HelpButtonVisibility="Visible" ApplicationButtonImageSource="Backstage_Icon.png"> 
    <telerik:RadRibbonTab Header="Home"> 
        <telerik:RadRibbonGroup> 
            <telerik:RadRibbonButton SmallImage="paste.png" Text="Paste" /> 
            <telerik:RadOrderedWrapPanel VerticalAlignment="Top"> 
            <telerik:RadRibbonButton SmallImage="copy.png" Text="Copy" /> 
            <telerik:RadRibbonButton SmallImage="cut.png" Text="Cut" /> 
            </telerik:RadOrderedWrapPanel> 
        </telerik:RadRibbonGroup> 
    </telerik:RadRibbonTab> 
    <telerik:RadRibbonTab Header="Insert" /> 
    <telerik:RadRibbonTab Header="References" /> 
</telerik:RadRibbonView> 

Next, we will create a DelegateCommand object.

Example 2: Define a DelegateCommand

public DelegateCommand OpenHelpPageCommand { get; set; } 
public MainPage() 
{ 
    InitializeComponent();  
 
    OpenHelpPageCommand = new DelegateCommand(ExecuteOpenHelpPage); 
    this.DataContext = OpenHelpPageCommand; 
    InputBindingCollection inputBindCollection = new InputBindingCollection(); 
    inputBindCollection.Add(new KeyBinding(this.OpenHelpPageCommand, new KeyGesture(Key.F1))); 
    CommandManager.SetInputBindings(this, inputBindCollection); 
} 
Public Property OpenHelpPageCommand() As DelegateCommand 
    Get 
        Return m_OpenHelpPageCommand 
    End Get 
    Set(value As DelegateCommand) 
        m_OpenHelpPageCommand = Value 
    End Set 
End Property 
Private m_OpenHelpPageCommand As DelegateCommand 
Public Sub New() 
    InitializeComponent() 
 
    OpenHelpPageCommand = New DelegateCommand(ExecuteOpenHelpPage) 
    Me.DataContext = OpenHelpPageCommand 
    Dim inputBindCollection As New InputBindingCollection() 
    inputBindCollection.Add(New KeyBinding(Me.OpenHelpPageCommand, New KeyGesture(Key.F1))) 
    CommandManager.SetInputBindings(Me, inputBindCollection) 
End Sub 
Public Property OpenHelpPageCommand() As DelegateCommand 
    Get 
        Return m_OpenHelpPageCommand 
    End Get 
    Set(value As DelegateCommand) 
        m_OpenHelpPageCommand = Value 
    End Set 
End Property 
Private m_OpenHelpPageCommand As DelegateCommand 
 
Public Sub New() 
    InitializeComponent() 
    OpenHelpPageCommand = New DelegateCommand(ExecuteCommandHandler, CanExecuteCommandHandler) 
    Me.DataContext = OpenHelpPageCommand 
End Sub 

The HelpCommand property will accept every object that implements the ICommand interface. The DelegateCommand class is one such implementation.

You can implement your logic in the Execute and CanExecute handlers of the DelegateCommand.

Example 3: Implement the Execute and CanExecute methods

private bool CanExecuteCommandHandler(object obj) 
{ 
    // Implement logic that checks if the button command can be executed 
    return true; 
} 
 
private void ExecuteCommandHandler(object obj) 
{ 
    // Implement the logic that should be executed when the button is clicked 
    MessageBox.Show("Help Command Executed"); 
} 
Private Function CanExecuteCommandHandler(obj As Object) As Boolean 
    ' Implement logic that checks if the button command can be executed' 
    Return True 
End Function 
 
Private Sub ExecuteCommandHandler(obj As Object) 
    ' Implement the logic that should be executed when the button is clicked' 
    MessageBox.Show("Help Command Executed") 
End Sub 

Finally, you can bind the command as demonstrated in Example 4.

Example 4: Binding the HelpCommand property to the custom command

<telerik:RadRibbonView HelpButtonVisibility="Visible" HelpCommand="{Binding}" /> 

In addition you can use the HelpCommandParameter and the HelpCommandTarget properties of the RadRibbonView in order to pass additional data to the command.

Find a runnable project of the previous example in the WPF Samples GitHub repository.

See Also

In this article