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

Button vs RadButton

10 Answers 280 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Tomas asked on 12 Apr 2011, 01:43 PM

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

10 Answers, 1 is accepted

Sort by
0
Accepted
Kiril Stanoev
Telerik team
answered on 14 Apr 2011, 02:32 PM
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
0
Suresh
Top achievements
Rank 1
answered on 16 Jun 2011, 06:39 PM
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. 
0
Accepted
Petar Mladenov
Telerik team
answered on 21 Jun 2011, 03:29 PM
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
0
Oliver
Top achievements
Rank 1
answered on 05 Aug 2011, 12:13 PM
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
0
Tomas
Top achievements
Rank 1
answered on 08 Aug 2011, 01:43 PM

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

0
Petar Mladenov
Telerik team
answered on 10 Aug 2011, 03:55 PM
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 >>

0
Jerry T.
Top achievements
Rank 1
answered on 28 Oct 2011, 08:13 PM
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
0
Petar Mladenov
Telerik team
answered on 02 Nov 2011, 02:39 PM
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 >>

0
Khin Sandar
Top achievements
Rank 1
answered on 28 Feb 2015, 05:07 PM
Hi,

How do I add dynamic events  to RadRibbon Buttons in Ribbon View Paint example? I tried to add command in ButtonTemplate but It's not working. But command is working with Add Tab button as in example.

<DataTemplate x:Key="ButtonTemplate">
                <telerik:RadRibbonButton Text="{Binding Text}" Size="{Binding Size}" CollapseToSmall="WhenGroupIsSmall"
                        SmallImage="{Binding SmallImage}" LargeImage="{Binding LargeImage}" Command="{Binding AddTab}"/>
            </DataTemplate>

Thanks in advance!

Sandra
0
Petar Mladenov
Telerik team
answered on 03 Mar 2015, 09:56 AM
Hello Khin,

To add events to controls which are placed in DataTemplates you can use EventToCommand patters. Its isdescribed in the following help article.

 Event To Command Behavior

Let us know if this helps you move forward.

Regards,
Petar Mladenov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Buttons
Asked by
Tomas
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Suresh
Top achievements
Rank 1
Petar Mladenov
Telerik team
Oliver
Top achievements
Rank 1
Tomas
Top achievements
Rank 1
Jerry T.
Top achievements
Rank 1
Khin Sandar
Top achievements
Rank 1
Share this question
or