RibbonCommand not found

I see that most WPF Ribbon examples use some code like

xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"

I get this error ... "Type" r: RibbonCommand "was not found. Make sure you do not have a reference to the assembly and that all reference assemblies have been built."

Using VS 2010, .NET 4.0.

I am trying to figure out how to add a button to a feed and execute a code / command when clicked.

Thank.

+5
source share
3 answers

If you are using the new Microsoft WPF Ribbon, the RibbonCommand type is removed. The Command property is now an ICommand type.

To install the command on RibbonButton, you can do the following:

<ribbon:RibbonButton Command="ApplicationCommands.Copy" />

or use any command that implements ICommand.

+9

ICommand .

.

public class MyCommand : ICommand
{
    public void Execute(object parameter)
    {
        string hello = parameter as string;
        MessageBox.Show(hello, "World");
    }

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public event EventHandler CanExecuteChanged;
}

.

<DockPanel.Resources>
    <local:MyCommand x:Key="mycmd"/>
</DockPanel.Resources>

xaml, .

<ribbon:RibbonButton Command="{StaticResource mycmd}" CommandParameter="Hello, command" Label="Copy" LargeImageSource="Images/LargeIcon.png"/> 
+3

You also need to reference the assembly in the project itself.

+1
source

All Articles