The property 'Default' is set more than once

I am adding fonts to my XF solution and following Adam Pedleys explanation here: xamarinhelp.com/custom-fonts-xamarin-forms/

When I use this code (from the link above),

<ResourceDictionary>
    <OnPlatform x:TypeArguments="x:String" x:Key="BoldFont">
        <On Platform="Android" Value="OpenSans-Bold.ttf#Open Sans" />
        <On Platform="UWP" Value="/Assets/OpenSans-Bold.ttf#Open Sans" />
        <On Platform="iOS" Value="OpenSans-Bold" />
    </OnPlatform>
    <OnPlatform x:TypeArguments="x:String" x:Key="NormalFont">
        <On Platform="Android" Value="OpenSans-Regular.ttf#Open Sans" />
        <On Platform="UWP" Value="/Assets/OpenSans-Regular.ttf#Open Sans" />
        <On Platform="iOS" Value="OpenSans-Regular" />
    </OnPlatform>
</ResourceDictionary>

I get an error on the second and third "<On Platform..."
The error is "The property 'Default' is set more than once".

I could use

<Setter Property="FontFamily" Value="{OnPlatform iOS='OpenSans-Bold', Android='OpenSans-Bold.ttf#Open Sans'}" />

on every style, that would work, but I would prefer to use the code from the link to only define my fonts one time and get the shorter style setter:

<Setter Property="FontFamily" Value="{StaticResource BoldFont}" />

Thanks :-)

Best Answer

  • GritWesselGritWessel US ✭✭
    Accepted Answer

    I'm on Xamarin Forms 3.6.0.264807 right now, and the errors are gone :-)
    It's nice that Xamarin fixed it

Answers

  • GritWesselGritWessel USMember ✭✭

    I just found out that it builds and runs. I just didn't try to hit run because of the errors.

    ... but I could be nice to get rid of the errors :-)

  • stesvisstesvis USMember ✭✭✭
    edited September 2018

    @GritWessel same here after i updated Xamarin.Forms to 3.2.0.839982.

    I believe you have to do this now (this is my scenario):

                <OnPlatform x:Key="latoRegular"  x:TypeArguments="x:String" Android="Lato-Regular.ttf#Lato-Regular" iOS="Lato-Regular">
                </OnPlatform>
    
  • GritWesselGritWessel USMember ✭✭

    @stesvis the Android and iOS tags are obsolete. When using your code VS does not give me errors for it, but I don't like the blue squiggly line telling me that the tag is obsolete.
    There must be a solution without squiggly lines and errors :-)

  • stesvisstesvis USMember ✭✭✭
    I don't have any warning underlines, did you install the latest VS 2017 v15.8.4?
    I had them before but with the latest VS and XF they are now gone.
  • NMackayNMackay GBInsider, University mod

    @GritWessel said:
    @stesvis the Android and iOS tags are obsolete. When using your code VS does not give me errors for it, but I don't like the blue squiggly line telling me that the tag is obsolete.
    There must be a solution without squiggly lines and errors :-)

    Noticed this too,, it sometimes disappears with compilation but it comes back. This xaml is valid and compiles fine

            <OnPlatform x:Key="MediumFontFamily" x:TypeArguments="x:String">
                <On Platform="iOS">SFProText-Medium</On>
                <On Platform="Android">Fonts/Roboto-Medium.ttf#Roboto</On>
                <On Platform="UWP">/Assets/Fonts/segoeuib.ttf#Segoe UI</On>
            </OnPlatform>
    

    @stesvis

    That's the deprecated API , again it will compile but that will eventually be removed so you should refactor although I guess they'll wait a while before dropping the old API, the API changes came out in Xamarin Forms 2.4.0 or around that time.

  • stesvisstesvis USMember ✭✭✭

    @NMackay I had it that way (your way) before, and then it started giving me warnings. When I went back to my way, it stopped complaining:

    How do we know that it's deprecated? Where can i check?

  • davefxydavefxy Member ✭✭

    I noticed that when the OnPlatform is used in the Xamarin Book samples, they do not get the warning. When I hover over the <OnPlatform on the samples Xaml page, I see Xamain.Forms.OnPlatform. However when I hover over the <OnPlatform on my Xaml pages, I see Xamarin.Forms.Xaml.OnPlatformExtension. How can I get my <OnPlatform Xaml reference to resolve to Xamain.Forms.OnPlatform.

  • cristian588cristian588 Member

    Hi i update from xamarin 3.4.0.1008975 to 3.5.0.129452 and work for me

  • GritWesselGritWessel USMember ✭✭
    Accepted Answer

    I'm on Xamarin Forms 3.6.0.264807 right now, and the errors are gone :-)
    It's nice that Xamarin fixed it

Sign In or Register to comment.