Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Could we pass listview item as command parameter on checkchanged event for Checkbox control

$
0
0

@Hello All,

I have below control in XAML, I want to pass Listview item as I change checkbox, I tried relative binding as below but I could get only CheckChangedEventArgs when event fired as command, I don't want to go under UI layer and stick to MVVM.. I read somewhere about switch that

You could use Behaviors to transform your Events into behaviors. Then you can use Commands and more importantly the CommandParameter with which you can specify the object that it is about. <

How could I specify object that it is about on CheckChanged Event

 <ListView
                        x:Name="InclusiveServiceList"
                        CachingStrategy="RecycleElement"
                        HeightRequest="{Binding TypeOfInclusiveServices.Count, Converter={StaticResource ItemsToHeightConverter}}"
                        ItemsSource="{Binding TypeOfInclusiveServices}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="50" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <CheckBox
                                            Grid.Column="0"
                                            HeightRequest="40"                                            
                                            IsChecked="{Binding IsChecked, Mode=TwoWay}"
                                            WidthRequest="40">
                                            <CheckBox.Behaviors>
                                                <Behavior:EventToCommandBehavior
                                                    Command="{Binding BindingContext.AdditionalServicesInProcedureChargeCommand, Source={x:Reference InclusiveServiceList}}"
                                                    CommandParameter="{Binding Source={x:Reference InclusiveServiceList}, Path=BindingContext.ItemSource}"
                                                    EventName="CheckedChanged" />
                                            </CheckBox.Behaviors>
                                        </CheckBox>
                                        <Label
                                            Grid.Column="1"
                                            Text="{Binding Description}"
                                            VerticalOptions="Center" />
                                    </Grid>
                                </ViewCell>

                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>