2016-11-18 52 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