We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Trying to add an ImageButton to an AccordionItem's content. But the command is not getting triggered in the viewmodel

How can I make an ImageButton inside an AccordionItem work? Go to the bottom of the code for the ImageButton

            <accordion:SfAccordion x:Name="accordion" BindableLayout.ItemsSource="{Binding Clients}">
                <BindableLayout.ItemTemplate>
                    <DataTemplate>
                        <accordion:AccordionItem>
                            <accordion:AccordionItem.Header>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>

                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>

                                    <StackLayout
                                        Grid.Column="0"
                                        Grid.Row="0"
                                        Grid.RowSpan="2"
                                        Padding="20, 10" >

                                        <Image
                                            HeightRequest="35"
                                            Source="ic_material_camera.png" />

                                    </StackLayout>

                                    <Label
                                        Grid.Column="1"
                                        Grid.Row="0"
                                        Text="{Binding Name}"
                                        TextColor="Black"
                                        FontAttributes="Bold"
                                        FontSize="20" />

                                    <Grid
                                        Grid.Column="1"
                                        Grid.Row="1">
                                        
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>

                                        <Label
                                            Grid.Column="0"
                                            VerticalOptions="Center"
                                            Text="6051514"
                                            FontSize="14" />

                                        <StackLayout
                                            Orientation="Horizontal"
                                            Grid.Column="1" >

                                            <Image
                                                VerticalOptions="Center"
                                                HeightRequest="20"
                                                Source="ic_material_location_red_A700.png" />

                                            <Label
                                                VerticalOptions="Center"
                                                Text="{Binding Location}"
                                                FontSize="14" />
                                        </StackLayout>

                                    </Grid>
                                </Grid>
                            </accordion:AccordionItem.Header>
                            <accordion:AccordionItem.Content>
                                <Grid
                                    BackgroundColor="Gray"
                                    Padding="0, 10" >
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>

                                    <ImageButton
                                        Grid.Column="0"
                                        HeightRequest="40"
                                        Source="ic_material_eye.png"
                                        BackgroundColor="Gray"
                                        VerticalOptions="Center"
                                        HorizontalOptions="End"
                                        Command="{Binding ShowClientDetailCommand}" />
                                    
                                    <ImageButton
                                        Grid.Column="1"
                                        HeightRequest="40"
                                        Source="ic_material_add.png"
                                        BackgroundColor="Gray"
                                        VerticalOptions="Center"
                                        HorizontalOptions="Start"/>
                                    
                                </Grid>
                            </accordion:AccordionItem.Content>
                        </accordion:AccordionItem>
                    </DataTemplate>
                </BindableLayout.ItemTemplate>
            </accordion:SfAccordion>

4 Replies

LN Lakshmi Natarajan Syncfusion Team December 23, 2019 09:42 AM UTC

Hi Santiago, 
  
Thank you for contacting Syncfusion support. 
  
We have checked the reported issue and we could not able to reproduce the reported issue from our end. We would like to let you know that ImageButton works fine and command triggered as expected for the ImageButton when loading in Header and also Content. 
  
<ImageButton HeightRequest="40" 
                WidthRequest="40" 
                Source="Details.png" 
                Command="{Binding Path=BindingContext.DetailsCommand, Source={x:Reference accordion}}"/>  
  
Note: AccordionItem will be the BindingContext for ImageButton. If you are having command in ViewModel, then you have to make binding as in the above code snippet. 
  
  
Regards, 
Lakshmi Natarajan 



SA Santiago December 23, 2019 10:40 AM UTC

Thanks! That worked. But the command is not receiving the instance of the Client. How should I bind CommandParameter?


SA Santiago December 23, 2019 10:43 AM UTC

Nevermind. CommandParameter={Binding} worked. Thanks!


LN Lakshmi Natarajan Syncfusion Team December 24, 2019 09:10 AM UTC

Hi Santiago, 
  
 
Thanks for the update. 
  
We are glad that reported issue have been resolved at your end. Please let us know if you need any further update. As always we are happy to help you out. 
  
 
Regards, 
Lakshmi Natarajan 


Loader.
Live Chat Icon For mobile
Up arrow icon