Giter VIP home page Giter VIP logo

how-to-use-custom-font-icon-in-.net-maui-expander's Introduction

how-to-use-custom-font-icon-in-.net-maui-expander

This example demonstrates about how to use the font icon in expander part of .NET MAUI Expander (SfExpander).

You can customize the expander header icon with font icons in .NET MAUI Expander. Please follow the steps below to use the font icons in the Expander Header element.

Step 1: Place the ttf file in the shared code project and set the Build action as MauiFont.

Step 2: In ResourceDictionary, define the font to use the custom font as StaticResource.

<ContentPage.Resources>
    <ResourceDictionary>
        <OnPlatform x:TypeArguments="x:String" x:Key="ExpanderIcon">
            <On Platform="Android" Value="ExpanderIcons.ttf#ExpanderIcons" />
            <On Platform="WinUI" Value="ExpanderIcons.ttf#ExpanderIcons" />
            <On Platform="iOS" Value="ExpanderIcons" />
            <On Platform="MacCatalyst" Value="ExpanderIcons"/>
        </OnPlatform>
    </ResourceDictionary>
    <local:ExpanderIconConverter x:Key="ExpanderIconConverter"/>
</ContentPage.Resources>

Step 3: Bind the FontFamily for Label using resource key. Use converter to display platform specific icons and bind the Device platform using RuntimePlatform to specify the platform in the ConverterParameter. Set HeaderIconPosition as None to hide the default Header icon.

<ContentPage.Content>
    <ScrollView BackgroundColor="#EDF2F5">
        <StackLayout>
            <syncfusion:SfExpander x:Name="expander1" HeaderIconPosition="None">
                <syncfusion:SfExpander.Header>
                    <Grid HeightRequest="50">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="70"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Label HorizontalOptions="Center" VerticalOptions="Center"
                         FontFamily="{StaticResource ExpanderIcon}"
                         Text="{Binding Path=IsExpanded,Source={x:Reference expander1}, Converter={StaticResource ExpanderIconConverter}}"/>
                        <Label Text="Veg Pizza" Grid.Column="1" TextColor="#495F6E"  VerticalTextAlignment="Center" />
                    </Grid>
                </syncfusion:SfExpander.Header>
                <syncfusion:SfExpander.Content>
                    <Grid Padding="10" BackgroundColor="#FFFFFF">
                        <Label BackgroundColor="#FFFFFF" HeightRequest="60" 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>
                </syncfusion:SfExpander.Content>
            </syncfusion:SfExpander>

            <syncfusion:SfExpander x:Name="expander2" HeaderIconPosition="None">
                <syncfusion:SfExpander.Header>
                    <Grid HeightRequest="50">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="70"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Label HorizontalOptions="Center" VerticalOptions="Center"
                            FontFamily="{StaticResource ExpanderIcon}"
                            Text="{Binding Path=IsExpanded,Source={x:Reference expander2}, Converter={StaticResource ExpanderIconConverter}, ConverterParameter={x:Static Device.RuntimePlatform}}"/>
                        <Label Text="Non-veg Pizza" Grid.Column="1" TextColor="#495F6E"  VerticalTextAlignment="Center" />
                    </Grid>
                </syncfusion:SfExpander.Header>
                <syncfusion:SfExpander.Content>
                    <Grid Padding="10" BackgroundColor="#FFFFFF">
                        <Label Text="Non-veg pizza is prepared by including the meat and animal tissue products." HeightRequest="50" TextColor="#303030" VerticalTextAlignment="Center"/>
                    </Grid>
                </syncfusion:SfExpander.Content>
            </syncfusion:SfExpander>
        </StackLayout>
    </ScrollView>
</ContentPage.Content>

Step 4: Converter to display icon.

public class ExpanderIconConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if ((bool)value)
        {
            return "\ue700";
        }
        else
        {             
            return "\ue701";
        }
    }

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

View sample in GitHub

Conclusion I hope you enjoyed learning about how to use a custom font icon for Expander in .NET MAUI (SfExpander). 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 for configuration specifications. You can also explore our .NET MAUI Expander example to understand how to create and manipulate data. 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!

how-to-use-custom-font-icon-in-.net-maui-expander's People

Contributors

piruthivirajm avatar syncfusionbuild avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.