Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Buttons > Button vs RadButton

Answered Button vs RadButton

Feed from this thread
  • Tomas avatar

    Posted on Apr 12, 2011 (permalink)

    Hi,

    I don't know if this is by design or not but I thought the default Silverlight button and the Telerik RadButton are supposed to work the same, but I've found a case where they're behaving differently.

    I have a button defined like this:

    <Button Content="..." Command="{Binding MyCommand}" IsEnabled="{Binding MyIsEnabledProperty}" />

    MyCommand is of type DelegateCommand but without a CanExecute specified.
    MyIsEnabledProperty is a simple boolean property.

    In this case the button is enabled or disabled depending on the value of MyIsEnabledProperty

    However if I change the button to a RadButton instead like this:

    <telerik:RadButton Content="..." Command="{Binding MyCommand}" IsEnabled="{Binding MyIsEnabledProperty}" />

    Then IsEnabled is not working as I would expect anymore, adding a CanExecute to my DelegateCommand makes it behave as
    expceted again.

    So it looks like the order in which properties are evaluated are differenet between the Button and RadButton.

    Tomas

    Reply

  • Answer Kiril Stanoev Kiril Stanoev avatar

    Posted on Apr 14, 2011 (permalink)

    Hello Tomas,

    Thank you for pointing out this inconsistency. Let me put my two cents in the topic. IMHO, mixing the Command and IsEnabled properties of a Button is not a good practice and we strongly advocate against it since the commanding mechanism internally controls the IsEnabled property of the Button. Therefore, a cleaner way will be to use the Command property and take advantage of the CanExecute method to control the IsEnabled property. Take for example the following scenario.

    public class ProductViewModel : INotifyPropertyChanged
    {
        private bool isLoadProperty;
     
        public ProductViewModel()
        {
            this.LoadCommand = new DelegateCommand(this.LoadProducts, this.CanLoadProducts);
        }
     
        public DelegateCommand LoadCommand { get; set; }
     
        private void LoadProducts(object param)
        {
     
        }
     
        private bool CanLoadProducts(object param)
        {
            return this.IsLoadEnabled;
        }
     
        public bool IsLoadEnabled
        {
            get
            {
                return this.isLoadProperty;
            }
            set
            {
                if (this.isLoadProperty != value)
                {
                    this.isLoadProperty = value;
                    this.LoadCommand.InvalidateCanExecute();
                    this.OnPropertyChanged("IsLoadEnabled");
                }
            }
        }
     
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyname)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyname));
            }
        }
    }

    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Width="200">
        <TextBlock Text="Button" />
        <Button Content="..." Command="{Binding LoadCommand}" />
        <TextBlock Text="RadButton" />
        <telerik:RadButton Content="..." Command="{Binding LoadCommand}" />
        <CheckBox IsChecked="{Binding IsLoadEnabled, Mode=TwoWay}" Content="IsLoadEnabled" />
    </StackPanel>

    Clicking the CheckBox will result in the following outcome. We will further investigate the topic and see why RadButton behaves differently than Button, but again, you should definitely consider not mixing Command and IsEnabled since this might lead to further issues.
    I'm attaching my test project as well. Please take a look at it and let me know what your thoughts are on the subject. I'd be glad to further continue the discussion with you.

    Regards,
    Kiril Stanoev
    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
    Attached files

    Reply

  • Posted on Jun 16, 2011 (permalink)

    I have the same issue with RadButton. I am able to disable the button if it were Button but not the RadButton. I have tried removing the IsEnabled property binding and disabled the command by making ICommand.CanExecute return false but didn't get through. 

    Reply

  • Answer Petar Mladenov Petar Mladenov admin's avatar

    Posted on Jun 21, 2011 (permalink)

    Hi Suresh,

    We are aware of this issues and we agree that this behavior is not acceptable in the RadButton. You can track this issue's status here and here. Unfortunately, we cannot provide an estimated time when they will be resolved.

    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

    Reply

  • Oliver avatar

    Posted on Aug 5, 2011 (permalink)

    this is my code in RelayCommand.
    how to change this code for using IsEnable in RadButton?
    please help me.
    -------------------------------------------------------------------------

    Imports System.Net
    Imports System.Windows
    Imports System.Windows.Controls

    Public Class RelayCommand
        Implements ICommand

        Private relayedAction As Action(Of Object)

        Public Sub New(ByVal relayedAction As Action(Of Object))
            Me.relayedAction = relayedAction
        End Sub

        Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
                Return True
        End Function

        Public Event CanExecuteChanged As EventHandler Implements System.Windows.Input.ICommand.CanExecuteChanged

        Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
            Me.relayedAction.Invoke(parameter)

        End Sub

    End Class

    Reply

  • Tomas avatar

    Posted on Aug 8, 2011 (permalink)

    Hi Kiril,

    Thanks for the reply and please apologize for my late reply. I'm okay with your answer I mostly wanted to give you a heads up as I think I've read somewhere that your controls works as the native silverlight controls and this behviour confused me at first. But your're probably right that you shouldn't mix the Command and IsEnabled.

    Thanks for the explanation.

    Tomas

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Aug 10, 2011 (permalink)

    Hello Tomas,

     @Oliver
    Could you please elaborate more on your scenario, how you use your RadButton and what exactly do you wish to achieve? Please keep in mind that is not good practice to use both CanExecute() and IsEnabled.Thank you for your cooperation.  

    Greetings,
    Petar Mladenov
    the Telerik team

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

    Reply

  • Posted on Oct 28, 2011 (permalink)

    What's the status of the RadButton and IsEnabled?

    The two PITS entries referenced above still show as Open and in the Q3 Beta the IsEnabled still has no effect on a telerik:RadButton

    Jerry

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Nov 2, 2011 (permalink)

    Hi Jerry T.,

     Yes, these bugs are still not resolved in the RadButton. Unfortunately, we cannot promise an estimated date when they will be fixed. Thank you for your understanding. 

    Regards,
    Petar Mladenov
    the Telerik team

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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Buttons > Button vs RadButton