开发者

RibbonCommand was not found

开发者 https://www.devze.com 2023-01-27 06:34 出处:网络
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 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 ass开发者_开发百科emblies 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.


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.


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"/> 


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

0

精彩评论

暂无评论...
验证码 换一张
取 消