How to customize the header icon in Xamarin.Forms Accordion?
You can customize the Xamarin.Forms SfAccordion header icon based on the expanded state by using the converter.
XAML
Bind the IsExpanded property to show different icons for expand and collapse. Set the HeaderIconPosition to None for the AccordionItem to hide the default header icon.
<syncfusion:SfAccordion Grid.Row="1" HeaderIconPosition="None">
<syncfusion:SfAccordion.Items>
<syncfusion:AccordionItem x:Name="accordionItem1">
<syncfusion:AccordionItem.Header>
<Grid HeightRequest="50">
<Label TextColor="#495F6E" Text="Cheese burger" VerticalTextAlignment="Center" Padding="5,0,0,0"/>
<Image Margin="10" HorizontalOptions="End" Source="{Binding IsExpanded,Source={x:Reference accordionItem1},Converter={StaticResource ExpanderIconConverter}}" HeightRequest="20" WidthRequest="20"/>
</Grid>
</syncfusion:AccordionItem.Header>
<syncfusion:AccordionItem.Content>
<Grid Padding="10,10,10,10" BackgroundColor="#FFFFFF">
<Label TextColor="#303030" Text="Hamburger accompanied with melted cheese. The term itself is a portmanteau of the words cheese and hamburger. The cheese is usually sliced, then added a short time before the hamburger finishes cooking to allow it to melt." VerticalTextAlignment="Center"/>
</Grid>
</syncfusion:AccordionItem.Content>
</syncfusion:AccordionItem>
</syncfusion:SfAccordion.Items>
</syncfusion:SfAccordion>
C#
Return image based on the IsExpanded property value.
public class ExpanderIconConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
return ImageSource.FromResource("AccordionXamarin.Images.ArrowDown.png");
else
return ImageSource.FromResource("AccordionXamarin.Images.ArrowUp.png");
}
}
Conclusion
I hope you enjoyed learning about how to customize the header icon in Xamarin.Froms Accordion (SfAccordion).
You can refer to our Xamarin.Forms Accordion feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!