RadMenuItem IsEnabled not refreshing consistently

3 posts, 0 answers
  1. Georg
    Georg avatar
    15 posts
    Member since:
    Nov 2007

    Posted 03 Oct 2018 Link to this post

    My undo menu item is defined like this:  

    <telerik:RadMenuItem
          Header="Undo"
       InputGestureText="Ctrl-Z"
       Command="{Binding UndoCommand}"
       IsEnabled="{Binding SelectedProjectCanUndo}"/>

     

    SelectedProjectCanUndo is a bool property on the DataContext for the main window containing the menu. I call PropertyChanged on the correct property name, and I can see that SelectedProjectCanUndo is called immediately after, on behalf of the binding. And yet the menu item does not refresh consistently. Sometimes it does, and sometimes it doesn't. I created a small similar "sandbox" application, but everything works fine there. Any ideas?


  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2215 posts

    Posted 04 Oct 2018 Link to this post

    Hi Georg,

    Without reproducing this I can't tell what happens, but here are my thoughts on this. Keep in mind that the CanExecute value of the ICommand implementation affects the IsEnabled property of the control. If the CanExecute returns false, the IsEnabled property will be set to False. Otherwise, the IsEnabled is set to True. If you don't implement the CanExecute handler of the command, the command is always executable and therefore the IsEnabled property won't be affected. With this in mind, it is possible that the CanExecute of the command to set the IsEnabled property in your original application. You can double check this. Additionally, if this happens the IsEnabled property will be set in code, which has a higher priority than the default one way binding from the code snippet. 

    What I could suggest you is to rely only on the CanExecute handler of the command and remove the IsEnabled binding. 

    Regards,
    Martin Ivanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Georg
    Georg avatar
    15 posts
    Member since:
    Nov 2007

    Posted 04 Oct 2018 in reply to Martin Ivanov Link to this post

    Thanks Martin - that was very helpful. I got rid of IsEnabled and added a call to CanExecuteChanged on the command, and now it's working.
Back to Top