如何启用功能区菜单?

时间:2009-10-16 09:14:05

标签: wpf xaml controls ribbon

<r:RibbonWindow.Resources>
    <ResourceDictionary>

        <!--Ribbon Commands-->
        <r:RibbonCommand x:Key="cmdPrint" CanExecute="RibbonCommand_CanExecute_Print" LabelTitle="Print" LabelDescription="Print" ToolTipTitle="Help" ToolTipDescription="This is used to Print" SmallImageSource="Images\printIcon.png" LargeImageSource="Images\printIcon.png" />
        <r:RibbonCommand x:Key="cmdExit" CanExecute="RibbonCommand_CanExecute_Close" LabelTitle="Close" LabelDescription="Close" ToolTipTitle="Help" ToolTipDescription="Close Application" SmallImageSource="Images\exitIcon.png" LargeImageSource="Images\exitIcon.png" />
        <r:RibbonCommand x:Key="cmdHelp" CanExecute="RibbonCommand_CanExecute_Help" LabelTitle="About" LabelDescription="Help" ToolTipTitle="Help" ToolTipDescription="About Application" SmallImageSource="Images\vdiWorksIcon.png" LargeImageSource="Images\vdiWorksIcon.png" />

        <!--Theme-->
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml" />
        </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>
</r:RibbonWindow.Resources>

<!--Root Grid-->
<Grid x:Name="LayoutRoot">




    <r:Ribbon Title="Protocol Inspector" x:Name="ribbon" BorderBrush="Orange">
        <r:Ribbon.SelectedTab>
            <r:RibbonTab/>
        </r:Ribbon.SelectedTab>

        <!--Quick Access Toolbar-->
        <r:Ribbon.QuickAccessToolBar>
            <r:RibbonQuickAccessToolBar>
                <r:RibbonButton Command="{StaticResource cmdExit}" />
                <r:RibbonButton Command="{StaticResource cmdPrint}" />
                <r:RibbonButton Command="{StaticResource cmdHelp}"/>
            </r:RibbonQuickAccessToolBar>
        </r:Ribbon.QuickAccessToolBar>

        <r:Ribbon.ApplicationMenu>                
            <r:RibbonApplicationMenu IsEnabled="True" >
              <r:RibbonApplicationMenu.Command>
                    <r:RibbonCommand Executed="RibbonCommand_Executed" SmallImageSource="Images\VdiworksIcon.png" LargeImageSource="Images\VdiworksIcon.png" />
                </r:RibbonApplicationMenu.Command>

                <r:RibbonApplicationMenuItem Command="{StaticResource cmdPrint}" />
                <r:RibbonApplicationMenuItem Command="{StaticResource cmdExit}" />
                <r:RibbonApplicationMenuItem Command="{StaticResource cmdHelp}" />

            </r:RibbonApplicationMenu>
        </r:Ribbon.ApplicationMenu>
        <r:RibbonTab x:Name="HomeTab" Label="Home" IsSelected="True">
            <r:RibbonGroup Name="FileGroup">
                <r:RibbonGroup.Command>
                    <r:RibbonCommand LabelTitle="Home" />
                </r:RibbonGroup.Command>
                <r:RibbonButton Name="menuExit" Content="Exit" Command="{StaticResource cmdExit}"/>
                <r:RibbonButton Name="menuPrint" Content="Print" Command="{StaticResource cmdPrint}"/>
            </r:RibbonGroup>
        </r:RibbonTab>
        <r:RibbonTab x:Name="HelpTab" Label="Help">
            <r:RibbonGroup Name="HelpGroup">
                <r:RibbonGroup.Command>
                    <r:RibbonCommand LabelTitle="Help" />
                </r:RibbonGroup.Command>

                <r:RibbonButton Name="menuAbout" Content="About" Command="{StaticResource cmdHelp}"/>
            </r:RibbonGroup>
        </r:RibbonTab>
    </r:Ribbon>

未启用菜单选项,禁用它们。

2 个答案:

答案 0 :(得分:1)

100%工作正确答案

<r:RibbonWindow.Resources>
    <ResourceDictionary>

        <r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdPrint" LabelTitle="Print" LabelDescription="Print" ToolTipTitle="Help" ToolTipDescription="This is used to Print" SmallImageSource="Images\printIcon.png" LargeImageSource="Images\printIcon.png" />
        <r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdExit" LabelTitle="Close" LabelDescription="Close" ToolTipTitle="Help" ToolTipDescription="Close Application" SmallImageSource="Images\exitIcon.png" LargeImageSource="Images\exitIcon.png" />
        <r:RibbonCommand Executed="RibbonCommand_Executed" x:Key="cmdHelp" LabelTitle="About" LabelDescription="Help" ToolTipTitle="Help" ToolTipDescription="About Application" SmallImageSource="Images\ICON.png" LargeImageSource="Images\ICON.png" />
        <r:RibbonCommand x:Key="testCmd" Executed="RibbonCommand_Executed" LabelTitle="Test Command" ToolTipDescription="test command" SmallImageSource="Images\ICON.png" LargeImageSource="Images\ICON.png"/>

        <!--Theme-->
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml" />
        </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>
</r:RibbonWindow.Resources>

答案 1 :(得分:0)

不要为Resources标记中的各个命令指定CanExecute和Executed事件处理程序,而是尝试将它们指定为CommandBindings

<r:Ribbon Title="Protocol Inspector" x:Name="ribbon" BorderBrush="Orange">
    <r:Ribbon.CommandBindings>
        <CommandBinding Command="{StaticResource cmdExit}" 
            CanExecute="cmdExit_CanExecute"
            Executed="cmdExit_Executed" />
    </r:Ribbon.CommandBindings>
...