Context Menu Initalization

Ribbon for WPF Forum

Posted 17 years ago by Bryan Livingston
Version: 1.0.0348
Platform: .NET 3.5
Environment: Windows XP (32-bit)
I've got an app that you can see at or

I'm using a context menu and the options on the menu are not initalizing correctly. When the app first starts all the context menu options are disabled, even though some of the same commands are enabled on the ribbon. The Paste and Gradient options should always be enabled.

They stay disabled until you create a new drawing and then close it. Running some other commands might also fix the menu. Once it's fixed it tends to stay fixed until the program is re-run.

Here is the xaml for the context menu:

        <ribbon:RibbonContextMenu Width="250">
            <ribbon:Button Command="ApplicationCommands.Cut" />
            <ribbon:Button Command="ApplicationCommands.Copy" />
            <ribbon:Button Command="ApplicationCommands.Paste" />
            <ribbon:Separator />
            <ribbon:MenuButton Label="Grouping" >            
                <ribbon:Button Command="{x:Static v:GroupCommand.Command}" />
                <ribbon:Button Command="{x:Static v:UngroupCommand.Command}" />
            <ribbon:MenuButton Label="Order" >
                <ribbon:Button Command="{x:Static v:BringToFrontCommand.Command}" />
                <ribbon:Button Command="{x:Static v:SendToBackCommand.Command}" />
                <ribbon:Button Command="{x:Static v:BringForwardCommand.Command}" />
                <ribbon:Button Command="{x:Static v:SendBackCommand.Command}" />
            <ribbon:MenuButton Label="Rotate" KeyTipAccessText="X">
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:RotateClockwiseCommand.Command}" />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:RotateCounterClockwiseCommand.Command}" />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:FlipVerticalCommand.Command}" />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:FlipHorizontalCommand.Command}" />
                <ribbon:Separator />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:RotateCommand.Command}" />
            <ribbon:MenuButton Label="Align" >
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:AlignLeftEdgeCommand.Command}" />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:AlignHorizontalCentersCommand.Command}" />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:AlignRightEdgeCommand.Command}" />
                <ribbon:Separator />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:AlignTopEdgeCommand.Command}" />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:AlignVerticalCentersCommand.Command}" />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:AlignBottomEdgeCommand.Command}" />
                <ribbon:Separator />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:DistributeHorizontalCommand.Command}" />
                <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:DistributeVerticalCommand.Command}" />
            <ribbon:Separator />
            <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:ScaleCommand.Command}" />
            <ribbon:Button KeyTipAccessText="X" Command="{x:Static v:SkewCommand.Command}" />
            <ribbon:Button KeyTipAccessText="S" Command="{x:Static v:GradientTool.ToolCommand}" />

This problem isn't happening with the sample app. I'm not sure how to get you a clear repro or where to start. The drawings in my program are created after the ribbon control and the main window are initalized.

Perhaps a workaround would be to call some initalization of some kind manually. What should I try?



Comments (1)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
If a Command is assigned to a button (ours work the same way as regular WPF buttons outside the main focus scope), a path must be found up to a handler of that command. If the WPF command routing architecture can't find that path then the related UI control (in this case ours) will appear disabled since WPF thinks that there is no handler for its click.

We've noticed some goofiness with WPF context menus and commands on them in the past too. A couple things you can do is ensure that keyboard focus is inside of a control that handles that command. That is rule #1 for making sure WPF commands work. The second thing you could try is providing a CommandTarget property. Here you can bind to whatever object handles the command if it isn't found along the routing path.

For instance when we build our ribbon control context menus (that allow you to minimize the ribbon, etc.), we have to set CommandTarget and point it to the Ribbon because normally the routing goes to the main document since Ribbon is outside of the main scope.

Hope that helps!

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.