How to customize header icon in .NET MAUI Expander (SfExpander)?
You can customize the .NET MAUI Expander header icon in the SfExpander.Header elements using the converter.
XAML
Binding the IsExpanded property to show different icons to expand and collapse. Set HeaderIconPosition to None to hide the default header icon.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.Expander;assembly=Syncfusion.Maui.Expander"
xmlns:local="clr-namespace:ExpanderMAUI"
x:Class="ExpanderMAUI.MainPage">
<ContentPage.Resources>
<ResourceDictionary>
<local:ExpanderIconConverter x:Key="ExpanderIconConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
<ScrollView BackgroundColor="#EDF2F5" Padding="0,30,0,0">
<StackLayout>
<syncfusion:SfExpander x:Name="expander1" HeaderIconPosition="None">
<syncfusion:SfExpander.Header>
<Grid HeightRequest="50">
<Label TextColor="#495F6E" Text="Veg Pizza" Padding="5,0,0,0" />
<Image Margin="10" HorizontalOptions="End" Source="{Binding IsExpanded,Source={x:Reference expander1},Converter={StaticResource ExpanderIconConverter}}" HeightRequest="20" WidthRequest="20"/>
</Grid>
</syncfusion:SfExpander.Header>
<syncfusion:SfExpander.Content>
<Grid Padding="10,10,10,10">
<Label TextColor="#303030" Text="Veg pizza is prepared with the items that meet vegetarian standards by not including any meat or animal tissue products." HeightRequest="50" VerticalTextAlignment="Center" />
</Grid>
</syncfusion:SfExpander.Content>
</syncfusion:SfExpander>
<syncfusion:SfExpander x:Name="expander2" HeaderIconPosition="None">
<syncfusion:SfExpander.Header>
<Grid HeightRequest="50">
<Label TextColor="#495F6E" Text="Non-veg Pizza" Padding="5,0,0,0" />
<Image Margin="10" HorizontalOptions="End" Source="{Binding IsExpanded,Source={x:Reference expander2},Converter={StaticResource ExpanderIconConverter}}" HeightRequest="20" WidthRequest="20"/>
</Grid>
</syncfusion:SfExpander.Header>
<syncfusion:SfExpander.Content>
<Grid Padding="10,10,10,10">
<Label TextColor="#303030" Text="Non-veg pizza is prepared by including the meat and animal tissue products." HeightRequest="50" VerticalTextAlignment="Center" />
</Grid>
</syncfusion:SfExpander.Content>
</syncfusion:SfExpander>
</StackLayout>
</ScrollView>
</ContentPage>
C#
Create a converter to return an image based on the IsExpanded property.
public class ExpanderIconConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
return "arrowdown.png";
else
return "arrowup.png";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Output:
Download the complete sample on GitHub
Conclusion
I hope you have enjoyed learning how to customize the header icon in .NET MAUI Expander.
You can refer to our .NET MAUI Expander feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications.
Check out our components from the License and Downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!