In this article, we demonstrate how to create an Expander with rounded corners in Xamarin.Forms using Syncfusion's SfExpander control. The sample showcases custom header and content styling, rounded corners, and dynamic icon changes based on expansion state. The implementation leverages PancakeView for advanced UI effects and value converters for dynamic properties.
To learn more about these features, check out the official user guide:
KB Link: View document in Syncfusion Xamarin Knowledge base
<syncfusion:SfExpander x:Name="expander1" HeaderIconPosition="None">
<syncfusion:SfExpander.Header>
<pancake:PancakeView CornerRadius="{Binding IsExpanded, Source={x:Reference expander1}, Converter={StaticResource CornerRadiusConverter}}" BackgroundColor="#bbbfca" HeightRequest="50">
<Grid>
<Label Text="Veg Pizza" TextColor="#495F6E" VerticalTextAlignment="Center" Margin="10,0,0,0"/>
<Image Margin="10" HorizontalOptions="End" HeightRequest="20" WidthRequest="20" Source="{Binding IsExpanded,Source={x:Reference expander1},Converter={StaticResource ExpanderIconConverter}}"/>
</Grid>
</pancake:PancakeView>
</syncfusion:SfExpander.Header>
<syncfusion:SfExpander.Content>
<pancake:PancakeView CornerRadius="0,0,20,20" BackgroundColor="#dddddd" >
<Grid Padding="10,10,10,10" >
<Label HeightRequest="50" Text="Veg pizza is prepared with the items that meet vegetarian standards by not including any meat or animal tissue products." TextColor="#303030" VerticalTextAlignment="Center"/>
</Grid>
</pancake:PancakeView>
</syncfusion:SfExpander.Content>
</syncfusion:SfExpander>
<syncfusion:SfExpander x:Name="expander2" HeaderIconPosition="None">
<syncfusion:SfExpander.Header>
<pancake:PancakeView CornerRadius="{Binding Path=IsExpanded, Source={x:Reference expander2}, Converter={StaticResource CornerRadiusConverter}}" BackgroundColor="#bbbfca" HeightRequest="50">
<Grid>
<Label Text="Non-veg Pizza" TextColor="#495F6E" VerticalTextAlignment="Center" Margin="10,0,0,0"/>
<Image Margin="10" HorizontalOptions="End" HeightRequest="20" WidthRequest="20" Source="{Binding IsExpanded, Source={x:Reference expander2},Converter={StaticResource ExpanderIconConverter}}"/>
</Grid>
</pancake:PancakeView>
</syncfusion:SfExpander.Header>
<syncfusion:SfExpander.Content>
<pancake:PancakeView CornerRadius="0,0,20,20" BackgroundColor="#dddddd" >
<Grid Padding="10,10,10,10">
<Label Text="Non-veg pizza is prepared by including the meat and animal tissue products." HeightRequest="50" TextColor="#303030" VerticalTextAlignment="Center"/>
</Grid>
</pancake:PancakeView>
</syncfusion:SfExpander.Content>
</syncfusion:SfExpander>
- Rounded corners: PancakeView is used to provide rounded corners for both the header and content of the Expander. The CornerRadius is dynamically set using a value converter based on the expansion state.
- Custom header and icon: The header includes a label and an icon that changes depending on whether the Expander is expanded or collapsed. This is achieved using ExpanderIconConverter and data binding to the IsExpanded property.
- Content styling: The content area uses PancakeView for rounded corners and a distinct background color, enhancing the visual separation between header and content.
- Multiple expanders: The sample demonstrates two expanders (Veg Pizza and Non-veg Pizza), each with its own header, icon, and content, showing how to reuse the same pattern for different sections.
I hope you enjoyed learning about how to to add rounded corners for Xamarin.Forms Expander (SfExpander).
You can refer to our Xamarin.Forms Expander 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 or Direct-Trac. We are always happy to assist you!