找不到RibbonCommand

我看到大多数WPF Ribbon示例都使用了一些代码
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
我收到此错误...“找不到类型'r:RibbonCommand'。确认您没有错过程序集引用,并且已经构建了所有引用的程序集。” 使用VS 2010,.NET 4.0。 我试图找出如何在功能区中添加按钮并在单击时执行代码/命令。 谢谢。     
已邀请:
如果您使用的是新的Microsoft WPF功能区,则已删除RibbonCommand类型。 Command属性现在是ICommand类型。 要在RibbonButton上设置命令,您可以执行以下操作:
<ribbon:RibbonButton Command="ApplicationCommands.Copy" />
或使用任何实现ICommand的命令。     
您还可以使用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"/> 
    
您还必须在项目本身中引用程序集。     

要回复问题请先登录注册