[英]How to create a custom font size in xaml using Xamarin, so that you can change font sizes depending on device?
有没有办法创建一个自定义字体大小,它的工作方式与 Xamarin 中已经内置的 Micro 或 Small 或 Title 相同。 我希望能够像下面这样使用它:
<Label Text="Test" FontSize="MyFontSize"/>
我认为它将在我的资源字典中实现如下内容,但它不起作用:
<FontSize x:Key="MyFontSize">
<OnPlatform x:TypeArguments="FontSize">
<On Platform="UWP">25</On>
<On Platform="iOS">12</On>
</OnPlatform>
</FontSize>
错误说:
“找不到类型 FontSize”
这不是运行时错误。 它只是 XAML 编辑器中的绿色下划线。
可以做到吗?
您需要使用x:Double
代替:
<OnPlatform x:Key="MyFontSize" x:TypeArguments="x:Double">
<On Platform="UWP">25</On>
<On Platform="iOS">12</On>
</OnPlatform>
然后像这样引用资源:
<Label Text="Test" FontSize="{StaticResource MyFontSize}"/>
或者您可以直接在视图上指定它:
<Label Text="Test">
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="UWP">25</On>
<On Platform="iOS">12</On>
</OnPlatform>
</Label.FontSize>
</Label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.