Articles in this section
Category / Section

How to customize header icon in .NET MAUI Expander (SfExpander)?

4 mins read

You can customize the .NET MAUI SfExpander 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.

<?xml version="1.0" encoding="utf-8" ?>
<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#

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 "arrowdown.png";
        else
            return "arrowup.png";
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Output:

ImageHeaderIcon.PNG

View Sample in GitHub

Conclusion
I hope you have enjoyed learning to create Expander application using C# in .NET MAUI.

You can refer to our .NET MAUI SfExpander 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!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied