Declined
Last Updated: 23 Mar 2020 11:06 by ADMIN
Currently IsCheckedChanged command is raised when the BindingContext of the CheckBox is updated and this is a change in the behavior compared to previous releases.
Declined
Last Updated: 02 Mar 2019 06:46 by Alejandro Genovesi

Hello!

When include a CheckBox inside a simple ListView (also with RadListView), and try implement the CheckBoxUserCommand Id="IsCheckedChanged" the control appears disabled.

I use MVVM and I need binding the checkedChanged Command to execute a custom operation related to specific row of the ListView; but, how can i know which element of the ListView affecting when checked  / unchecked the CheckBox. Here the code:

PD: Then prefix name of  <checkBoxComamnds:CheckBoxUserCommand>  is wrong, should be <checkBoxCommands: > (Error in word: Comamnds...)

XAML

<AbsoluteLayout BindingContext ="{Binding ViewModel}">      
        <ListView IsRefreshing="{Binding IsRefreshing, Mode=TwoWay}"
                ItemsSource="{Binding CalendarList}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                       <ViewCell>
                            <Grid>
                                <Grid.RowDefinitions >
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width = "Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions >
                                 < !--Calendar checkBox Selector -->
                                <telerikPrimitives:RadCheckBox
                                      x:Name="checkViewCalendar">
                                    <telerikPrimitives:RadCheckBox.Commands>
                                        <checkBoxComamnds:CheckBoxUserCommand
                                              Command = "{Binding IsCheckedChangedCommand}"
                                              Id="IsCheckedChanged" 
                                              SuppressDefaultCommand="True">
                                        </checkBoxComamnds:CheckBoxUserCommand>
                                    </telerikPrimitives:RadCheckBox.Commands>
                                </telerikPrimitives:RadCheckBox>
                                <!-- Name of Agenda -->
                                <Label
                                    Grid.Row="0"
                                    Grid.Column="1"
                                    HorizontalOptions="FillAndExpand"
                                    Text="{Binding Name}">
                                </Label>
                           </Grid >
                      </ViewCell >
                   </DataTemplate >
               </ListView.ItemTemplate >
           </ListView >
</AbsoluteLayout>

MVVM Code


namespace ViewModels
{
   //using ...
    using System.Windows.Input;
    using Xamarin.Forms;
    using Telerik.XamarinForms.Primitives.CheckBox.Commands;

    public class CalendarsViewModel : BaseViewModel
        
       public CalendarsViewModel()
        {
            this.IsCheckedChangedCommand = new Command<CheckBoxIsCheckChangedCommandContext>(this.CheckBoxChange);
            this.LoadCalendars();
        }

       private async void CheckBoxChange(CheckBoxIsCheckChangedCommandContext context)
        {
            await Application.Current.MainPage.DisplayAlert(
                    "MVVM Alert Start",
                    $"CheckBox User Command executed at {DateTime.Now.ToLocalTime()} in {context.ToString()}",
                    "Ok");
           //How identify the container row in the context?
        }
        public ICommand IsCheckedChangedCommand { get; set; }

        public ObservableCollection<Calendar> CalendarList
        {
            get { return this.calendars; }
            set { SetValue(ref this.calendars, value); }
        }
        private async void LoadCalendars()
        {
           // API Call to get List and create ObservableCollection Binding to ListView
        }
Thanks for your help!