您好,我正在尝试使用以下代码将自定义字体应用于标签

    <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ExerClub.Pages.Profile" Title="Profile">
  <StackLayout>
    <Label Text="Login">
      <Label.FontFamily>
        <OnPlatform x:TypeArguments="x:String">
          <OnPlatform.iOS>MarkerFelt-Thin</OnPlatform.iOS>
          <OnPlatform.Android></OnPlatform.Android>
          <OnPlatform.WinPhone></OnPlatform.WinPhone>
        </OnPlatform>
      </Label.FontFamily>
    </Label>
    <Label Text="Club Name"/>
    <Label Text="More randomness"/>

  </StackLayout>
</ContentPage>


背后的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace ExerClub.Pages
{
    public partial class Profile : ContentPage
    {
        public Profile()
        {
            InitializeComponent();
        }
    }
}


取自Xamarin.forms Documentation

我在iOS上收到以下错误

System.ArgumentException: Object of type 'System.String' cannot be converted to type 'Xamarin.Forms.View'.


我是Xamarin的新手,并不真正理解为什么这可能会失败。

最佳答案

您需要放置字体名称<x:String>fontName</x:String>标记或简单地编写如下:

<Label Text="Login">
  <Label.FontFamily>
  <OnPlatform x:TypeArguments="x:String"
              iOS="MarkerFelt-Thin" Android=""
              WinPhone=""/>
  </Label.FontFamily>
</Label>

关于c# - Xamarin.forms自定义字体异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40677048/

10-13 06:20
查看更多