如何在RibbonMenuButton中定义Command和CommandTarget

时间:2014-08-10 11:35:07

标签: wpf xaml

早上好;我的应用程序WPF / C#我使用Ribbon控件,我想为我的RibbonMenuButton定义一个Cammand和CommandTarget。

我有这段代码,但我的命令不起作用:(

 <RibbonMenuButton LargeImageSource="Resources/Images/new.png" Label="New" KeyTip="N" >
                    <RibbonMenuButton.ItemContainerStyle>
                        <Style TargetType="MenuItem">
                            <Setter Property="Command" Value="{x:Static ApplicationCommands.New}" />
                            <Setter Property="CommandTarget" Value="{Binding ElementName=MyDesigner}"/>
                        </Style>
                    </RibbonMenuButton.ItemContainerStyle>
                </RibbonMenuButton>

你能帮助我吗?

1 个答案:

答案 0 :(得分:2)

我的问题解决了这样:

<RibbonTab Header=" File ">
            <RibbonGroup Header="File">

                <RibbonButton  Command="{x:Static ApplicationCommands.New}" CommandTarget="{Binding ElementName=MyDesigner}"  LargeImageSource="Resources/Images/new.png" Label="New" KeyTip="N"></RibbonButton>

                <RibbonButton SmallImageSource="Resources/Images/Open-3.png" Label=" Open " Command="{x:Static ApplicationCommands.Open}" CommandTarget="{Binding ElementName=MyDesigner}"/>
                <RibbonButton SmallImageSource="Resources/Images/Save_black-128.png" Label=" Save " Command="{x:Static ApplicationCommands.Save}" CommandTarget="{Binding ElementName=MyDesigner}"/>
                <RibbonButton SmallImageSource="Resources/Images/Print-icon.png" Label=" Print " Command="{x:Static ApplicationCommands.Print}" CommandTarget="{Binding ElementName=MyDesigner}"/>
            </RibbonGroup>

我已将RibbonMenuButton更改为RibbonButton(使用LargeImageSource以使用RibbonMenuButton保留相同的演示文稿).... RibbonButton还可以定义Command和CommandTarget :)