在我的 Xamarin Forms 项目中,我想为每个平台定义 Form 系列 onect 并在应用程序中使用它。
到目前为止,我已经对每个控件类型的 FontFamily 进行了硬编码
<Style x:Key="TahomaBase_Label" TargetType="Label" BaseResourceKey="SubtitleStyle">
<Setter Property="FontFamily" Value="Tahoma" />
...
</Style>
是否可以在我的 XAML 代码中全局设置字体系列,最好是OnPlatform
tag?
在 App.xaml 中定义样式,然后在整个应用程序中引用该样式。这样,您可以使用 OnPlatform 标记在 App.xaml 中设置一次字体,而不必担心所有其他 XAML 文件中的 OnPlatform。
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="PlatformFontSample.App">
<Application.Resources>
<ResourceDictionary>
<OnPlatform x:Key="FontFamilyName" x:TypeArguments="x:String" iOS="MarkerFelt-Thin" Android="OpenSans" WinPhone="Segoe UI" />
<Style x:Key="FontLabel" TargetType="Label">
<Setter Property="FontFamily" Value="{DynamicResource FontFamilyName}" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
进而:
<Label Text="{Binding Name}" Style="{DynamicResource FontLabel}" FontSize="Medium" FontAttributes="Bold" LineBreakMode="NoWrap"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)