SplitButton IsEnabled is ignored when a Command is used

6 posts, 0 answers
  1. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 11 May 2011 Link to this post

    Hi,

    I have this XAML:

    <telerik1:RadSplitButton 
        Content="Some Label"
        IsEnabled="{Binding SomeProperty}"
        Command="{Binding MyCommand}"
    ....

    Where MyCommand is a DelegateCommand class where the CanExecute method returns True. The problem is that the IsEnabled in the XAML is ignored and the button is always enabled even if SomeProperty's value is false.

    This is unexpected because it does not happen with other controls like the standard Button. I was going to post a bug report but I am not sure if this is by design.

    Jose
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 16 May 2011 Link to this post

    Hi Jose Simas,

    The behavior you have encountered is expected. The way to disable your RadButton (or RadSplitButton in your case) when using ICommand is to return false in the CanExecute method. For example like so:
    <telerik:RadSplitButton Command="{Binding MyCommand}" 
                                  CommandParameter="ParameterValue"
                                  Content="RadButton"
                                   />

    this.MyCommand = new DelegateCommand((a) => { MessageBox.Show(a.ToString()); }, x => { return false; });
    Let us know if you need more info on this.


    Kind regards,
    Petar Mladenov
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 16 May 2011 Link to this post

    Hi Petar Mladenov,

    Thank you for your answer. I have come across several occasions where CanExecute is not enough and I need to disable the button depending on the outcome of some unrelated process. With a regular button I bind IsEnabled to a property that triggers a PropertyChanged and thus can change the button state any time I need. With the SplitButton I cannot do this and I have to forego commands and use events instead.

    Best Regards,
    Jose
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 May 2011 Link to this post

    Hi Jose Simas,

    We had a discussion and we logged this issue as a bug in our PITS(Buttons: IsEnabled property should be with higher priority than returned value from CanExecute method of a Command) where you are able to track its status. We also updated your telerik account points.
    Thank you for your cooperation.

    Best wishes,
    Petar Mladenov
    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
  6. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 23 Feb 2012 Link to this post

    In your Property Setter can you not call InvalidateCanExecute (if using Telerik's DelegateCommand) after you set the property. Then CanExecute can return true or false based on the new value of the property. This would sync the change of the property to the CanExecute method for the command. You could actually call InvalidateCanExecute anytime you need within your ViewModel to enable/disable the command and thus the button.

    Might be a work around til they can elevate the IsEnabled priority.
  7. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 27 Feb 2012 Link to this post

    Hello,
    The problem with the IsEnabled and CanExecute is fixed in our latest official build (Q1 2012) and I've attached a sample project which demonstrates this.
    If you have more questions please feel free to ask.

    Kind regards,
    Zarko
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
UI for WPF is Visual Studio 2017 Ready