Ribbon and CommandBinding CanExecute

Ribbon for WPF Forum

Posted 10 years ago by BODY
Avatar
Hi All,

We have some problems with a command binding.
We created a Ribbon with few button like that:

 <ribbon:Group Label="Gestion des fichiers" Width="120">
        <StackPanel>
            <ribbon:PopupButton Label="Nouveau" ImageSourceLarge="../../Img/new-file.png" >
                <ribbon:Menu x:Name="NewFileMenu"/>
            </ribbon:PopupButton>
            <ribbon:PopupButton Label="Ajouter" ImageSourceLarge="../../Img/add-file.png" >
                <ribbon:Menu x:Name="AddFileMenu"/>
            </ribbon:PopupButton>
        </StackPanel>
    </ribbon:Group>
When the tab containing these buttons is hidden, the CanExecute is evaluated.
Otherwise, is not. Do you have some ideas about this ??

private void FileAddCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = MainController.Project != null;
}

<CommandBinding Command="{x:Static Local:CustomCommands.FileAdd}"
                        CanExecute="FileAddCommand_CanExecute"
                        Executed="FileAddCommand_Executed"/>

Comments (1)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi,

Since Ribbon's often contain hundreds of commands we added a feature to lessen the impact of can-executes continuously firing (which could slow down an app's typing, etc.) by adding a property to button controls called CanUpdateCanExecuteWhenHidden. It returns false by default. You could override any button class and change it to true if you want to have your CanExecute handlers called even when it is hidden.


Actipro Software Support

The latest build of this product (v2019.1 build 0685) was released 13 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.