Changes to IsEnabled causing odd behavior

2 posts, 0 answers
  1. Michael MSTG
    Michael MSTG avatar
    46 posts
    Member since:
    Aug 2012

    Posted 12 May 2011 Link to this post

    On a previous thread, Hristo posted the following:
    "We made some changes in IsEnabled property - when you set it to False then RadMenuItem will be disabled no matter what ICommand CanExecute return. But if IsEnabled is True then IsEnabled actual value will be based on ICommand CanExecute result. That is why probably we clear your binding. Please specify Binding Mode=TwoWay so that Binding will not be removed internally."

    Since this change we seem to be experiencing some issues with toggling IsEnabled on an ICommand object. 

    We bind the menu control within a HierarchicalDataTemplate with the following container binding:
    <telerik:ContainerBinding PropertyName="IsEnabled" Binding="{Binding AllowAccess}" />

    I've also tried the following:
    <telerik:ContainerBinding PropertyName="IsEnabled" Binding="{Binding AllowAccess, Mode=TwoWay}" />

    The allow access property is read-only and is internally set to true or false when the page is created (in this example, I did verify it was always going to return true). The menu item has a command bound to it with CanExecute initially to false.  As expected, the menu item is disabled as CanExecute is evaluated as soon as I hover on the menu. Once I've done something on the screen where the ICommand object should re-evaluate whether it can execute now, hovering on the menu once again does not seem to re-execute CanExecute of the command object so it is never re-evaluated as expected to true and re-enable the item.  I did try to make the AllowAccess binding two way with no luck.

    I also set it up so the initial value of CanExecute on the screen to true which left the menu item enabled as expected (again evaluated as soon as I hovered on the menu. Once I performed an action on the screen that would make the command re-evaluate CanExecute to false, the menu did not re-evaluate but the command did once I clicked on it (in other words the menu item should have been disabled and not allowed me to click on it).  With CanExecute back to false, I once again changed the screen to be true yet the menu item never re-enabled.

    Shouldn't the menu re-execute CanExecute on each ICommand object to check if it hasn't changed since the initial "IsEnabled" of the menu item was set to true?
  2. Hristo
    Hristo avatar
    832 posts

    Posted 16 May 2011 Link to this post

    Hello Michael,

    One of the changes was to reduce the number of ICommand CanExecute method calls. Now we cache the result of the method if the state of RadMenuItem is valid (e.g. its Loaded and if there is parent this parent is opened). This change was done for compatibility and performance reasons.

    Now when some action state change (can be executed or not) you have to manually raise CanExecuted event of ICommand. This way all controls that are bound to this command will enable or disable based on the CanExecute result. I think that this is the correct way.

    Let us know if you need more information.

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top