StaticResource OnPlatform for FontFamily

GabrielBunselmeyerGabrielBunselmeyer Member ✭✭
edited January 11 in Xamarin.Forms

So my app uses the Hero custom font. I can declare it just fine this way:

<Style ApplyToDerivedTypes="True" TargetType="Label">
                <Setter Property="TextColor" Value="{StaticResource TextWhite}"/>
                <Setter Property="FontFamily">
                    <Setter.Value>
                        <OnPlatform x:TypeArguments="x:String">
                            <On Platform="iOS" Value="Hero"/>
                            <On Platform="Android" Value="Hero.otf#Hero"/>
                        </OnPlatform>
                    </Setter.Value>
                </Setter>
            </Style>

However, to be able to use it on different spots throughout the app (such as an Autocomplete field from Syncfusion, which has like 3 different FontFamily properties), I wanted to create a separate StaticResource just for the OnPlatform, like this:

        <OnPlatform x:Key="OnPlatformHeroFont" x:TypeArguments="x:String">
                <On Platform="iOS" Value="Hero"/>
                <On Platform="Android" Value="Hero.otf#Hero"/>
            </OnPlatform>

And then use a reference to it (Value="{StaticResource OnPlatformHeroFont}") both in the Syncfusion field and in the other Styles in the App.xaml file:

<Style ApplyToDerivedTypes="True" TargetType="Label">
                <Setter Property="TextColor" Value="{StaticResource TextWhite}"/>
                <Setter Property="FontFamily" Value="{StaticResource OnPlatformHeroFont}"/>
</Style>

However, this gives me a "Java.Lang.RuntimeException: Font asset not found Hero.otf#Hero" exception, while that first example (declared inside a style's setter tag) doesn't. Any ideas?

And yes, the font is inside of the Assets folder. As I said, it works fine in that first example.
Also, works fine on iOS.

Tagged:

Best Answer

  • edited January 14 Accepted Answer

    @jezh said:
    Where is the Assets folder placed?

    Could you please post a basic a demo so that we can test with it?

    In the normal directory, the root for the Android project (xx.Android).

    However, after some more testing, it seems to be a problem on Syncfusion's end. This works just fine with default Xamarin Forms views. Sorry for the unnecessary thread.

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    Where is the Assets folder placed?

    Could you please post a basic a demo so that we can test with it?

  • GabrielBunselmeyerGabrielBunselmeyer Member ✭✭
    edited January 14 Accepted Answer

    @jezh said:
    Where is the Assets folder placed?

    Could you please post a basic a demo so that we can test with it?

    In the normal directory, the root for the Android project (xx.Android).

    However, after some more testing, it seems to be a problem on Syncfusion's end. This works just fine with default Xamarin Forms views. Sorry for the unnecessary thread.

Sign In or Register to comment.