xamarin.forms - 无法分配属性“FontFamily”:属性不存在
问题描述
嗨,Xamarin.forms 的新样式。我有这个旧的 xamarin.forms 应用程序,我进行了调试,但在 App.xaml 中的以下样式出现此错误
问题:位置 39:17。无法分配属性“FontFamily”:属性不存在,或不可分配,或值和属性之间的类型不匹配
请帮忙。
<!-- Application resource dictionary -->
<ResourceDictionary>
<!-- colors -->
<!--<Color x:Key="HeaderTextColor">#585858</Color>
<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>
<!-- font families -->
<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" />
<!-- fonts -->
<Font
x:Key="HeaderFont"
FontFamily="{StaticResource MediumFontFamily}"
FontSize="30" />
<Font
x:Key="SubHeaderFont"
FontFamily="{StaticResource MediumFontFamily}"
FontSize="18" />
<Font
x:Key="TitleFont"
FontFamily="{StaticResource MediumFontFamily}"
FontSize="20" />
<Font
x:Key="BodyFont"
FontFamily="{StaticResource RegularFontFamily}"
FontSize="18" />
<!-- styles -->
<Style x:Key="PageHeaderLabel" TargetType="Label">
<Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
<Setter Property="Font" Value="{StaticResource HeaderFont}" />
</Style>
<Style x:Key="SubHeaderLabel" TargetType="Label">
<Setter Property="TextColor" Value="{StaticResource BodyTextColor}" />
<Setter Property="Font" Value="{StaticResource SubHeaderFont}" />
</Style>
<Style x:Key="ClassTimeLabel" TargetType="Label">
<Setter Property="TextColor" Value="{StaticResource TimeColor}" />
<Setter Property="Font" Value="{StaticResource TitleFont}" />
</Style>
<Style x:Key="ClassNameLabel" TargetType="Label">
<Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
<Setter Property="Font" Value="{StaticResource TitleFont}" />
</Style>
<Style x:Key="ClassInstructorLabel" TargetType="Label">
<Setter Property="TextColor" Value="{StaticResource BodyTextColor}" />
<Setter Property="Font" Value="{StaticResource BodyFont}" />
</Style>
</ResourceDictionary>
</Application.Resources>
//--- 更新:我改变了这部分:我仍然有错误
<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>
解决方案
非常接近,但不是Font
用于Double
定义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>
推荐阅读
- angular - AngularFire2 app.auth 不是函数
- c# - 为什么其他语句不起作用/执行?C#
- excel - 用“” Excel VBA查找并替换任何字母和后面的所有内容
- javascript - JSON字符串不止一章转javascript对象
- python - 如何让 Platypus 创建的 shell 应用程序响应键盘命令?
- git - 如何回到之前在 Git 上的分离头提交?
- tabs - 实现标签不滚动
- javascript - 使用 forLoop() 在数组中查找唯一编号
- android - arrayadapter 和 recyclerview.adapter 有什么区别?
- php - 如何在 codeigniter 中调用我的库函数?