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

SfAccordion Manually Collapse from codebehind

Hello,

Is there is a way to collapse the content of selected item from code behind?

I have a button in the accordion content and i want to collapse the selected item after finishing its task from MVVC , i do every thing and task run successfully and the accordion header updated succesfully with the updated data , i just need to fire collapse event of this item after finishing the task;

Thanks.

4 Replies

GP Gnana Priya Namasivayam Syncfusion Team December 12, 2019 04:37 PM UTC

Hi Mohammed, 
 
Thanks for using Syncfusion product. 
 
Currently, we are validating the reported query from our side. We will validate and provide you further details on December 13,2019. We will appreciate your patience until then. 
 
 
Regards, 
Gnana Priya N 



GP Gnana Priya Namasivayam Syncfusion Team December 13, 2019 01:53 PM UTC

Hi Mohammed, 
 
We would like to inform that you can achieve your requirement binding the IsExpand property of AccordionItem like below. We have attached the model sample based on your requirement. Kindly find the sample and code snippet from below. 
 
 
 
Xaml 
 
<syncfusion:SfAccordion x:Name="Accordion" ExpandMode="MultipleOrNone" BindableLayout.ItemsSource="{Binding Info}"> 
        <BindableLayout.ItemTemplate> 
            <DataTemplate> 
                <syncfusion:AccordionItem IsExpanded="{Binding IsExpand}"> 
                    <syncfusion:AccordionItem.Header> 
                        <Label Text="{Binding Name}"/> 
                    </syncfusion:AccordionItem.Header> 
                    <syncfusion:AccordionItem.Content> 
                        <Grid> 
                            <Grid.RowDefinitions> 
                                <RowDefinition Height="50"/> 
                                <RowDefinition Height="50"/> 
                            </Grid.RowDefinitions> 
                        <Label Text="{Binding Description}"/> 
                            <Button x:Name="btn" Grid.Row="1" Text="{Binding Name}" Command="{Binding Path=BindingContext.ButtonCommand, Source={x:Reference Accordion}}" CommandParameter="{x:Reference btn}"/> 
                        </Grid> 
                    </syncfusion:AccordionItem.Content> 
                </syncfusion:AccordionItem> 
            </DataTemplate> 
        </BindableLayout.ItemTemplate> 
    </syncfusion:SfAccordion> 
 
 
ViewModel.cs 
 
public class ItemInfoRepository : INotifyPropertyChanged 
{ 
        public ObservableCollection<ItemInfo> Info { get; set; } 
        public Command<object> ButtonCommand { get; set; } 
        public ItemInfoRepository() 
        { 
            Info = new ObservableCollection<ItemInfo>(); 
            ButtonCommand = new Command<object>(OnButtonTapped); 
        } 
 
        private void OnButtonTapped(object obj) 
        { 
            var item = (obj as Button).BindingContext as ItemInfo; 
            item.IsExpand = !item.IsExpand; 
        } 
 
} 
 
 
 
Please let us know whether sample meets your requirement. 
 
Regards, 
Gnana Priya N 
 
 



MO mohamed December 13, 2019 06:08 PM UTC

Hello,

Thanks alot the sample works and your solustion is just PERFECT for me thanks, that what i was looking  for.


GP Gnana Priya Namasivayam Syncfusion Team December 16, 2019 05:38 AM UTC

Hi Mohammed, 
 
Thanks for the update. 
 
We are glad that reported issue have been fixed in your application. Please let us know if you need any further assistance from us. 
 
Regards, 
Gnana Priya N 


Loader.
Up arrow icon