WPF Ribbon: Issues with Routing Commands

Nov 19, 2008 at 8:33 PM
I posted earlier that commands were not properly routing through the visual hierarchy when the command was executed from the ribbon.  I thought I fixed this issue by setting FocusManager.IsFocusScope to true.  This seems to be consistent with menu bars and toolbars.  But now I am running into issues with button dropdowns.  All of my button dropdowns are initially disabled until I initially click on the ribbon.  Then the drop downs enables and the commands properly route.

Is it correct to set FocusManager.IsFocusScope to true for the ribbon?
And if it is correct, is there a way to get the drop down buttons enabled initially?

Jan 7, 2009 at 6:15 PM
Command routing relies on focus. It sounds like your application does not start with an initially focused element. Thus, when CanExecute is raised, it doesn't go anywhere, so everything is disabled. For commands, like Copy and Paste, this makes sense since you need something to be focused. For other commands, like Open and Save, this isn't the case. In a later release, you will be able to set a CommandTarget property, which will allow you to not need focus within the tree. So, commands like Open and Save would target something like the main window, where handlers will be to open and save documents.

For now, when your application starts, try calling Focus() directly on a convenient element in the tree.