将命令与C#中的RadRibbonView按钮一起使用,而不是XAML

将命令与C#中的RadRibbonView按钮一起使用,而不是XAML,c#,wpf,xaml,mvvm,telerik,C#,Wpf,Xaml,Mvvm,Telerik,我正在尝试让MVVM(非常新)和RadRibbonView一起工作。问题是,我使用的是带有MVVM模型的标准WPF应用程序 在我以前拥有的XAML文件中 <Menu> <MenuItem Header="{x:Static properties:Resources.FileMenu}"> <MenuItem Header="{x:Static properties:Resources.FileMenuNewWo

我正在尝试让MVVM(非常新)和RadRibbonView一起工作。问题是,我使用的是带有MVVM模型的标准WPF应用程序

在我以前拥有的XAML文件中

<Menu>
            <MenuItem Header="{x:Static properties:Resources.FileMenu}">
                <MenuItem Header="{x:Static properties:Resources.FileMenuNewWorkflow}" Command="{Binding Path=NewWorkflowCommand}" InputGestureText="Ctrl+N"/>
                <MenuItem Header="{x:Static properties:Resources.FileMenuNewService}" Command="{Binding Path=NewServiceCommand}" InputGestureText="Shift+Ctrl+N"/>
                <MenuItem Header="{x:Static properties:Resources.FileMenuOpen}" Command="{Binding Path=OpenWorkflowCommand}" InputGestureText="Ctrl+O"/>
                <Separator/>
                <MenuItem Header="{x:Static properties:Resources.FileMenuSave}" Command="{Binding Path=SaveWorkflowCommand}" InputGestureText="Ctrl+S"/>
                <MenuItem Header="{x:Static properties:Resources.FileMenuSaveAs}" Command="{Binding Path=SaveAsWorkflowCommand}"/>
                <MenuItem Header="{x:Static properties:Resources.FileMenuSaveAll}" Command="{Binding Path=SaveAllWorkflowsCommand}" InputGestureText="Shift+Ctrl+S"/>
                <Separator/>
                <MenuItem Header="{x:Static properties:Resources.FileMenuAddReference}" Command="{Binding Path=AddReferenceCommand}"/>
                <Separator/>
                <MenuItem Header="{x:Static properties:Resources.FileMenuClose}" Command="{Binding Path=CloseWorkflowCommand}"/>
                <MenuItem Header="{x:Static properties:Resources.FileMenuCloseAll}" Command="{Binding Path=CloseAllWorkflowsCommand}"/>
                <Separator/>            
        </Menu>
telerik MVVM功能区示例中的当前按钮视图模型是

    public class ButtonViewModel : ViewModelBase
        {
            private String text;
            private ButtonSize size;
            private string smallImage;
            private string largeImage;
//perhaps work something with this...
            private RelayCommand command;    

            /// <summary>
            ///     Gets or sets Text.
            /// </summary>
            public String Text
            {
                get
                {
                    return this.text;
                }
                set
                {
                    if (this.text != value)
                    {
                        this.text = value;
                        this.OnPropertyChanged("Text");
                    }
                }
            }

            public ButtonSize Size
            {
                get
                {
                    return size;
                }
                set
                {
                    size = value;
                }
            }

            public string SmallImage
            {
                get
                {
                    return smallImage;
                }
                set
                {
                    smallImage = value;
                }
            }

            public string LargeImage
            {
                get
                {
                    return largeImage;
                }
                set
                {
                    largeImage = value;
                }
            }
        }
public类按钮viewmodel:ViewModelBase
{
私有字符串文本;
私人纽扣大小;
私有字符串图像;
私有字符串大图像;
//也许可以用这个做点什么。。。
专用中继命令;
/// 
///获取或设置文本。
/// 
公共字符串文本
{
得到
{
返回此.text;
}
设置
{
if(this.text!=值)
{
this.text=值;
本条关于财产变更(“文本”);
}
}
}
公用钮扣尺寸
{
得到
{
返回大小;
}
设置
{
大小=值;
}
}
公共字符串图像
{
得到
{
返回图像;
}
设置
{
smallImage=值;
}
}
公共字符串大图像
{
得到
{
返回大图像;
}
设置
{
大图像=值;
}
}
}
因此,所有组的创建都在ModelView中。问题是我不知道如何让命令工作。我有一个RelayCommand类来处理命令

从以下链接: 是否可以只调用类RelayCommand(基本上与链接中的示例相同),这样我就不必做太多更改,只需从上面的函数调用命令?类似openFile.Execute()之类的东西

大多数问题是如何将XAML连接到命令。所有菜单项现在都是C#格式的,并且希望在那里有一个命令定义


感谢您的帮助

你可以在这里查看我是如何做到这一点的:谢谢。我再次认为绑定在XAML文件中。我正在考虑在C#文件中调用或绑定,因为组按钮都是在ModelView类中定义的。
<telerik:RadRibbonView Grid.Row="0" x:Name="ribbonView" ApplicationName="MyApp" ItemsSource="{Binding Tabs}"
                               ApplicationButtonContent="File" Title="{x:Static properties:Resources.RibbonViewTitle}" ItemTemplate="{StaticResource TabTemplate}"
                               SelectedItem="{Binding SelectedTab, Mode=TwoWay}"
                               MinimizeButtonVisibility="Visible" HelpButtonVisibility="Visible">
private GroupViewModel GetFilesGroup()
    {
        GroupViewModel fileItems = new GroupViewModel();
        fileItems.Text = "File";
        SplitButtonViewModel newFile = new SplitButtonViewModel();
        newFile.Text = "New";
        newFile.Size = ButtonSize.Large;
        newFile.LargeImage = GetPath("MVVM/new.png");
        fileItems.Buttons.Add(newFile);


        SplitButtonViewModel openFile = new SplitButtonViewModel();
        openFile.Text = "Open";
        openFile.Size = ButtonSize.Large;
        openFile.LargeImage = GetPath("MVVM/open.png");
        fileItems.Buttons.Add(openFile);

        ButtonGroupViewModel buttonsGroup = new ButtonGroupViewModel();
        buttonsGroup.Buttons.Add(GetButton("save", "Save"));
        buttonsGroup.Buttons.Add(GetButton("SaveAll", "Save All"));
        buttonsGroup.Buttons.Add(GetButton("SaveAs", "Save As"));

        fileItems.Buttons.Add(buttonsGroup);
        return fileItems;
    }
    public class ButtonViewModel : ViewModelBase
        {
            private String text;
            private ButtonSize size;
            private string smallImage;
            private string largeImage;
//perhaps work something with this...
            private RelayCommand command;    

            /// <summary>
            ///     Gets or sets Text.
            /// </summary>
            public String Text
            {
                get
                {
                    return this.text;
                }
                set
                {
                    if (this.text != value)
                    {
                        this.text = value;
                        this.OnPropertyChanged("Text");
                    }
                }
            }

            public ButtonSize Size
            {
                get
                {
                    return size;
                }
                set
                {
                    size = value;
                }
            }

            public string SmallImage
            {
                get
                {
                    return smallImage;
                }
                set
                {
                    smallImage = value;
                }
            }

            public string LargeImage
            {
                get
                {
                    return largeImage;
                }
                set
                {
                    largeImage = value;
                }
            }
        }