RibbonCommand was not found

我只是一个虾纸丫 提交于 2019-12-03 08:21:56

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!