Commands in Application Menu

Ribbon for WPF Forum

Posted 16 years ago by Tore Aurstad
Version: 3.5.0429
I am using RibbonCommands in my Main window and the buttons of my Application Menu
use these Commands to figure out which text to set and icon, plus the Executed and CanExecute events. I am having trouble with CanExecute not firing when I select a new
section in my Main window. If I just click directly on a section and nothing else, my buttons in the Application Menu is still disables.

- However - If I click somewhere in the Main window, the buttons are activated, i.e. the CanExecute event is fired. I have set up my command bindings on the Main Window, so I guess this is to be expected. Question is, if I click on a section (I use Actipro Navigation to the left, just the module selector seen in Outlook 2007) directly without clicking on somewhere on the GUI, how do I get the buttons activated? I have tried CommandManager or focus trick programmatically. I don't seem to be able to send the event to the main window so the CanExecute can be launched...

Some info - I use WPF and .NET 3.5.1, Visual Studio 2008 and Actipro Ribbon and Navigation version 3.5 (latest patches applied), and Windows Vista Business.

Tore Aurstad,
Developer in Lydia Facility Management Systems,

Comments (6)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Tore,

Could you please put together a sample project that reproduces the issue you are seeing. It is hard to determine what the problem is from just your description.

Actipro Software Support

Posted 16 years ago by Tore Aurstad
Actually, a sample project of the system would be hard, as it is really big, I can however sum up the dilemma:

I got an application menu with several buttons, they are linked to commands, for example:

<ribbon:Button x:Name="ribbonAppMenuFooterButtonsOptionsBtn" Command="recourcesFiles:LydiaCommands.ShowOptions"
FontSize="11" Padding="0" Height="23" Foreground="DarkBlue" FontWeight="Normal"/>

This button is the options button, which is among the buttons disabled. In my main window the commandbinding looks like this:

<CommandBinding Command="recourcesFiles:LydiaCommands.ShowOptions" Executed="ShowOptions_Executed" CanExecute="LydiaCommand_Always_CanExecute" />

The CanExecute simple just consists of this:
private void LydiaCommand_Always_CanExecute(object sender, CanExecuteRoutedEventArgs e)
e.CanExecute = true;

The problem now is the following, I use Actipro Navigation also. When I click on one of my modules directly without "touching" the main GUI, I somehow seem to not be able to get the command activated. The problem dissapears when I click physically on the navigationbutton. I want to fix this programatically, such that users don't get buttons in the Application Menu disabled.

I have tried the following:
a) Trying CommandManager's static method for invalidate commands.
b) Trying to set the focus programatically.
c) Trying setting CommandTarget.
d) Trying to set focus on the Main Window programatically.

Have you got other suggestions for this problem? The problem I think is simple for those akin to commands, ribboncommands, CanExecute and WPF, if you got a solution I would be very glad.

Tore Aurstad,
Developer at Lydia FM
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Is the NavigationBar hosted in a separate window? I'm not exactly sure what you mean by the "main GUI" and "modules", and don't know how they are connected.

You may want to read the Commanding Overview (external link to MSDN) topic.

I can tell you is that since you do not specify the CommandTarget (the element on which the command is executed), the element with keyboard focus will be used as the command target. So in this case, if the associated command would always be handled by the window, then maybe you would want to set that as the command target. But again, this depends on your setup.

You said you tried this in item (c) above, but how did you set the CommandTarget?

Actipro Software Support

Posted 16 years ago by Tore Aurstad
Everything is in the same window, I tried setting the command target to main window.
I will look at the link provided, "Commanding Overview", I have read some of it previous. I will also look up RoutedEvents, and notify you if I find a solution.

Is the Navigationbar buttons sending events up the tree? If they are set to e.Handled automatically, the Window will not receive CanExecuteChanged Events for instance?

Tore Aurstad,
Developer, Lydia Facility Management,
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
The NavigationBar only handles the commands defined in the NavigationCommands class, all of which are specifically created for the NavigationBar.

If you can email some additional information or source to our support address, then we can take a look. We'd love to help you resolve this, but with the limited information it is difficult.

Actipro Software Support

Posted 15 years ago by Anurodh Ora

I am also facing the same problem and really appreciate if you can post the solution.

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.