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

checkbox event (MVVM)

1 Answer 1059 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 26 Jun 2018, 07:25 AM

Hello, i have no idea how to get the checked/unchecked event in mvvm. My goal is that i wan't do do some cell item calculation when rows are selected/deselected.

Here is my code:

<telerik:GridViewDataColumn DataMemberBinding="{Binding IsActive}" Header="" HeaderCellStyle="{StaticResource HeaderCellStyleGrid1}" ColumnGroupName="GruppenBezeichnung" Width="25">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                                <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}">
                                    <telerik:EventToCommandBehavior.EventBindings>
                                        <telerik:EventBinding Command="{Binding OnGridSelectionChangedCommand}" EventName="Checked" PassEventArgsToCommand="True" />
                                    </telerik:EventToCommandBehavior.EventBindings>
                                </CheckBox>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>

 

There is also a CheckboxColumn. Would this be a better approach and how get the checked/unchecked event?

<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsActive, Mode=TwoWay}" Header="" AutoSelectOnEdit="True" EditTriggers="CellClick" HeaderCellStyle="{StaticResource HeaderCellStyleGrid1}" ColumnGroupName="GruppenBezeichnung" Width="25"/>

 

Thank you and please can you show me a example.

Greetings RG

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 27 Jun 2018, 11:23 AM
Hello Richard,

Defining the CheckBox in the CellTemplate or CellEditTemplate will be the more flexible approach when it comes to subscribing to events and customizing the checkbox. I prepared a small example based on your code. I hope that helps.

An alternative approach would be to call the Execute method of the command in the setter of the IsActive property instead of using the events. For example:
private bool isActive;
public bool IsActive
{
    get { return isActive; }
    set
    {
        isActive = value;
        OnPropertyChanged("IsActive");
         
        ExecuteGridSelectionChangedAction();       
    }
}
I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Richard
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or