2016-11-18 113 views
0

你好我想用下面的代码应用自定义字体的标签Xamarin.forms自定义字体异常

<?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新手,不太明白为什么这可能会失败。

+0

能否请您显示完整的页面?除非我忽略了某些事情,否则错误似乎不是来自这里。 –

+0

我在后面添加了代码。我没有真正改变任何东西,教程也没有提及任何东西。 – xerotolerant

+0

您是否使用NuGet的最新版Xamarin.Forms?如果没有,更新和重建。 – therealjohn

回答

1

你需要把字体名称<x:String>fontName</x:String>标签或干脆写象下面这样:

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

这不完全是解决方案。这个问题对我来说是一个愚蠢的错误,但是为了这样做更容易,更方便。官方文件太复杂了。 – xerotolerant