locked
Execute a command on CheckboxMVVM RRS feed

  • Question

  • Hello Everybody !!

    I'm trying to execute a command on ListView for getting the selected item.

    Here is my 1st XAML Code : 

       <ListView ItemsSource="{Binding AzardsCollection}" 
                          MaxHeight="650"
                          IsItemClickEnabled="True"
                          x:Name="HazardListView"
                          SelectionMode="Single"
                          helpers:ItemClickCommandHelper.Command="{Binding HazardSelectedChangedCommand}"
                          ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollMode="Auto">
    
                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment"
                                    Value="Stretch" />
    
                            <Setter Property="Padding"
                                    Value="0" />
                            <Setter Property="Margin"
                                    Value="-5, 0, 10, 15" />
    
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <CheckBox Content="{Binding Name}"
                                      RequestedTheme="Light"
                                      Style="{StaticResource CheckBoxStyleBlue}"
                                      IsChecked="{Binding IsSelected, Mode=TwoWay}">
                                
    
                            </CheckBox>
    
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

    Here is my 2nd XAML Code : 

     <ListView ItemsSource="{Binding AzardsCollection}" 
                          MaxHeight="650"
                          IsItemClickEnabled="True"
                          x:Name="HazardListView"
                          SelectionMode="Single"
                          
                          ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollMode="Auto">
                    <i:Interaction.Behaviors>
                        <core:EventTriggerBehavior EventName="Tapped">
                            <core:InvokeCommandAction Command="{Binding HazardSelectedChangedCommand}"
                                                       />
                        </core:EventTriggerBehavior>
                    </i:Interaction.Behaviors>
                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment"
                                    Value="Stretch" />
    
                            <Setter Property="Padding"
                                    Value="0" />
                            <Setter Property="Margin"
                                    Value="-5, 0, 10, 15" />
    
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <CheckBox Content="{Binding Name}"
                                      RequestedTheme="Light"
                                      Style="{StaticResource CheckBoxStyleBlue}"
                                      IsChecked="{Binding IsSelected, Mode=TwoWay}">
                                
    
                            </CheckBox>
    
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

    My second code launch me a cast exception.

    My objectif is to retrieve the value of selected checkbox on my ListView

    Someone has an idea please?

    Thanks

    Wednesday, October 7, 2015 9:01 AM

Answers