简体   繁体   中英

XLabs ExtendedLabel change fonts does not work in Xamarin.Forms for UWP app

ITNOA

I have Xamarin forms project and I want to use ExtendedLabel for use own custom fonts in PCL project. when I follow ExtendedLabel instruction every things is ok for Droid project but when I want to run UWP project I see my fonts dose not apply for any label . the interesting note is when I use Xamarin built-in label and set FontFamily property with font name.ttf#friendly name pattern every things is ok for UWP project but ExtendedLabel does not show correct fonts in UWP app.

Dose anyone have idea to resolve UWP project problem?

I am using:

Visual Studio 2015 update 3
Xamarin forms 2.3.0.107
XLabs forms 2.2.0-pre5

thx

Dose anyone have idea to resolve UWP project problem

Ref this document

For Android and iOS platform, we can use FontName property, but for Windows Phone platform, it uses FriendlyFontName property:

Quote:

This property is only necessary for the Windows Phone platform. This can be found on the first line of the font or in the font preview. If not given then the file name excluding the extension is used. However this cannot be guaranteed to work.

But seems like XLabs didn't handle the FriendlyFontName setting correctly. I just tried its official sample for UWP

For the ExtendedLabel scenario, the font setting is incorrect.

After some investigations, based on this issue , I found a workaround to fit Windows Phone and UWP scenario.

Setting FontName and using OnePlatform for WINRT scenario in xaml:

 <controls:ExtendedLabel FontName="Kristen ITC"
                                      FontSize="20"
                                      FriendlyFontName="Kristen ITC"
                                      HorizontalOptions="StartAndExpand"
                                      Text="This uses 'FontName' = 'Kristen ITC' set in XAML and 'OnPlatform' properties, size 20">
                <controls:ExtendedLabel.FontFamily>
                  <OnPlatform x:TypeArguments="x:String"
                              iOS=""
                              Android=""
                              WinPhone="Kristen ITC"/>
                </controls:ExtendedLabel.FontFamily>              
</controls:ExtendedLabel>

Please notice that the specific Font should be installed in your platform OS.

Screenshot: 在此处输入图片说明

Check my forked repository

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM