Xamarin.forms 无法分配属性“FontFamily”:属性不存在

Xamarin.forms 无法分配属性“FontFamily”:属性不存在,xamarin.forms,Xamarin.forms,嗨,Xamarin的新风格。我有一个旧的xamarin.forms应用程序,我做了一个调试,我在app.xaml中得到了以下样式的错误 问题:位置39:17。无法分配属性FontFamily:属性不存在或不可分配,或者值和属性之间的类型不匹配 请帮忙 //--更新:我更改了此部分:我仍然有错误 <ResourceDictionary> <Color x:Key="BodyTextColor">#C3C3C3</Color&

嗨,Xamarin的新风格。我有一个旧的xamarin.forms应用程序,我做了一个调试,我在app.xaml中得到了以下样式的错误

问题:位置39:17。无法分配属性FontFamily:属性不存在或不可分配,或者值和属性之间的类型不匹配

请帮忙

//--更新:我更改了此部分:我仍然有错误

           <ResourceDictionary>

        <Color x:Key="BodyTextColor">#C3C3C3</Color>-->

        <Color x:Key="TimelineColor">#E4B6C3</Color>
        <Color x:Key="HeaderTextColor">#3C3C3C</Color>
        <Color x:Key="BodyTextColor">#869EAC</Color>
        <Color x:Key="TimeColor">#A64C79</Color>

       <OnPlatform
            x:Key="RegularFontFamily"
            x:TypeArguments="x:String"
            Android="sans-serif"
            iOS="HelveticaNeue" />
        <OnPlatform
            x:Key="LightFontFamily"
            x:TypeArguments="x:String"
            Android="sans-serif-light"
            iOS="HelveticaNeue-Light" />
        <OnPlatform
            x:Key="MediumFontFamily"
            x:TypeArguments="x:String"
            Android="sans-serif-medium"
            iOS="HelveticaNeue-Medium" />


        <x:Double x:Key="HeaderFontSize">30</x:Double>
        <x:Double x:Key="SubHeaderFontSize">18</x:Double>
        <x:Double x:Key="BodyFontSize">18</x:Double>
         <x:Double x:Key="TitleFontSize">20</x:Double>



        <Style x:Key="PageHeaderLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
            <Setter Property="Font" Value="{StaticResource HeaderFont}" />
            <Setter Property="FontSize" Value="{StaticResource HeaderFontSize}" />
        </Style>

        <Style x:Key="SubHeaderLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource BodyTextColor}" />
            <Setter Property="Font" Value="{StaticResource SubHeaderFont}" />
            <Setter Property="FontSize" Value="{StaticResource SubHeaderFontSize}" />
        </Style>

        <Style x:Key="ClassTimeLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource TimeColor}" />
            <Setter Property="Font" Value="{StaticResource TitleFont}" />
            <Setter Property="FontSize" Value="{StaticResource TitleFontSize}" />
        </Style>

        <Style x:Key="ClassNameLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
            <Setter Property="Font" Value="{StaticResource TitleFont}" />
            <Setter Property="FontSize" Value="{StaticResource TitleFontSize}" />
        </Style>

        <Style x:Key="ClassInstructorLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource BodyTextColor}" />
            <Setter Property="Font" Value="{StaticResource BodyFont}" />
            <Setter Property="FontSize" Value="{StaticResource BodyFontSize}" />
        </Style>

        <Style x:Key="TitleFont" TargetType="Label">
           <Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
           <Setter Property="Font" Value="{StaticResource MediumFontFamily}" />
          <Setter Property="FontSize" Value="{StaticResource TitleFontSize}" />
       </Style>

    </ResourceDictionary>

</Application.Resources>

非常接近,但是使用Double代替Font来定义FontSize,例如:

<OnPlatform
    x:Key="MediumFontFamily"
    x:TypeArguments="x:String"
    Android="sans-serif-medium"
    iOS="HelveticaNeue-Medium" />
现在,您应该定义具体的大小:

<x:Double x:Key="TitleFontSize">20</x:Double>
下一步消费它:

<Style x:Key="TitleFont" TargetType="Label">
    <Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
    <Setter Property="FontFamily" Value="{StaticResource MediumFontFamily}" />
    <Setter Property="FontSize" Value="{StaticResource TitleFontSize}" />
</Style>

我有点迷路了。我是删除字体部分中的所有字体,还是只删除字体中声明的大小?你能告诉我怎么做吗。Thanks替换all by并在样式中指定FontSize,就像我在回答中演示的那样。这很简单,一旦你得到它。我仍然有错误。请纠正我的错误。像海德方。为什么?我更新了我的答案。除此之外,问题是显而易见的,你必须注意字体的设置:1它应该是FontFamily,2它应该指向现有的资源。目前仍有一些指向旧字体定义,如HeaderFont。刚刚更新。为了避免我犯任何错误。你能纠正我的错误,制作一个样式并粘贴到这里,这样我就可以复制并粘贴到我的项目中。我对这种语法很陌生。你是说我不应该用Font=?改用Fontname?
<Style x:Key="TitleFont" TargetType="Label">
    <Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
    <Setter Property="FontFamily" Value="{StaticResource MediumFontFamily}" />
    <Setter Property="FontSize" Value="{StaticResource TitleFontSize}" />
</Style>
<OnPlatform x:TypeArguments="x:String" x:Key="default-font">
  <On Platform="Android" Value="sans-serif-medium" />
  <On Platform="iOS" Value="sans-serif-medium" />
</OnPlatform>