This is a migrated thread and some comments may be shown as answers.

RadMenuItem IsEnabled not refreshing consistently

2 Answers 52 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Georg
Top achievements
Rank 1
Veteran
Georg asked on 03 Oct 2018, 06:13 PM

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 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 04 Oct 2018, 09:25 AM
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.
0
Georg
Top achievements
Rank 1
Veteran
answered on 04 Oct 2018, 04:59 PM
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.
Tags
Menu
Asked by
Georg
Top achievements
Rank 1
Veteran
Answers by
Martin Ivanov
Telerik team
Georg
Top achievements
Rank 1
Veteran
Share this question
or