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;
}
}
|