RibbonCommand was not found
Asked Answered
D

3

6

I see the majority of WPF Ribbon examples out there use some code like

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

I'm getting this error..."The type 'r:RibbonCommand' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built."

Using VS 2010, .NET 4.0.

I'm trying to figure out how to add a button to the ribbon and execute code/command when it's clicked.

Thanks.

Disembroil answered 24/11, 2010 at 14:37 Comment(2)
Also getting RibbonGroupSizeDefinitionCollection doesn't exist in namespace. I downloaded this walkthrough from MS and I'm getting the same errors. Something is wrong with my machine?windowsclient.net/downloads/folders/hands-on-labs/…Disembroil
RibbonCommand class doesn't exist in msdn.microsoft.com/en-us/library/…Disembroil
A
9

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

To set the command on a RibbonButton, you can do the following:

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

or use any command that implements ICommand.

Almonry answered 2/12, 2010 at 21:14 Comment(0)
I
3

You also can use ICommand to implement your own command.

This class should be in code behind.

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;
}

You need to have Resources for using this command.

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

You also need to modify your xaml element to call this command.

<ribbon:RibbonButton Command="{StaticResource mycmd}" CommandParameter="Hello, command" Label="Copy" LargeImageSource="Images/LargeIcon.png"/> 
Illegal answered 30/8, 2011 at 20:2 Comment(0)
M
2

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

Memento answered 24/11, 2010 at 14:39 Comment(1)
Forgot to mention that I'm already doing that. Project is referencing RibbonControlsLibrary (C:\Program Files\Microsoft Ribbon for WPF\V4.0\RibbonControlsLibrary.dll).Disembroil

© 2022 - 2024 — McMap. All rights reserved.