mvvm canExecute InvalidateRequerySuggested

2 posts, 1 answers
  1. Benny
    Benny avatar
    8 posts
    Member since:
    Sep 2012

    Posted 30 May 2012 Link to this post

    I can't get the contextmenu to Reevaluate canExecute.
    What is the best practise to get contextMenu to evaluate CanExecute every time it's open. (So it's enable when it's supposed to be enabled...)

    <Grid x:Name="LayoutRoot">
        <TextBlock Text="RightClick me">
            <telerik:RadContextMenu x:Name="ContextMenu" GotFocus="ContextMenu_GotFocus">
                <telerik:RadMenuItem Header="Remove" Name="MnuRemove" Command="{Binding Remove}" CommandParameter="{Binding guid}"  />
    private void ContextMenu_GotFocus(object sender, RoutedEventArgs e)
    public DelegateCommand Remove { get; private set; }
        public Viewmodel()
            this.Remove = new DelegateCommand(OnRemove, CanRemove);
        private bool CanRemove(object obj)
            bool cr = ((DateTime.Now.Second % 2) == 0);
            return cr;
        private void OnRemove(object parameter)
  2. Answer
    Ivo avatar
    390 posts

    Posted 04 Jun 2012 Link to this post

    Hello Benny,

    CommandManager.InvalidateRequerySuggested() is designed to be used with RoutedCommands and not DeleagateCommands. In order to invalidate a DelegateCommand you will have to call the InvalidateCanExecute method of the concrete command.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top