In Development
Last Updated: 15 Apr 2024 11:56 by ADMIN
Apoorva
Created on: 01 Mar 2024 13:50
Category: CheckBox
Type: Feature Request
0
CheckBox: Expose command that executes when checkbox state changes

Expose command that executes when checkbox state changes.

Currently I am using EventToCommandBehavior:

 

    <VerticalStackLayout>
        <telerik:RadCheckBox x:Name="checkbox">
            <telerik:RadCheckBox.Behaviors>
                <telerik:RadEventToCommandBehavior EventName="IsCheckedChanged" Command="{Binding CheckedCommand}" />
            </telerik:RadCheckBox.Behaviors>
        </telerik:RadCheckBox>
    </VerticalStackLayout>

 

 

public class ViewModel : NotifyPropertyChangedBase
{
    public ViewModel()
    {
        this.CheckedCommand = new Command<IsCheckedChangedEventArgs>(this.CheckBoxUserCommand);
    }

    private void CheckBoxUserCommand(IsCheckedChangedEventArgs obj)
    {
        // logic here:
    }

    public ICommand CheckedCommand { get; set; }  
}

 

 

 

1 comment
ADMIN
Didi
Posted on: 04 Mar 2024 11:46

Another option is using the community toolkit event to command behavior: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/behaviors/event-to-command-behavior 

The xaml:

<VerticalStackLayout>
    <telerik:RadCheckBox x:Name="checkbox">
        <telerik:RadCheckBox.Behaviors>
            <telerik:RadEventToCommandBehavior EventName="IsCheckedChanged" 
                                                Command="{Binding CheckedCommand}" />
        </telerik:RadCheckBox.Behaviors>
    </telerik:RadCheckBox>

    <telerik:RadCheckBox x:Name="telerik">
        <telerik:RadCheckBox.Behaviors>
            <toolkit:EventToCommandBehavior EventName="IsCheckedChanged"
                                            CommandParameter="{Binding IsChecked,Source={x:Reference telerik}}"
                                            Command="{Binding SelectDateCommand}"/>
        </telerik:RadCheckBox.Behaviors>
    </telerik:RadCheckBox>
</VerticalStackLayout>

and the ViewModel where the RelayCommand attribute is used: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/relaycommand 

public partial class ViewModel : NotifyPropertyChangedBase
{
    public ViewModel()
    {
        this.CheckedCommand = new Command<IsCheckedChangedEventArgs>(this.CheckBoxUserCommand);
    }
    [RelayCommand]
    private void SelectDate(bool? state)
    {
        
    }
    private void CheckBoxUserCommand(IsCheckedChangedEventArgs obj)
    {

    }

    public ICommand CheckedCommand { get; set; }
}

Regards,
Didi
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com