问题描述
[assembly: ExportFont("Roboto-Regular.ttf",Alias ="Roboto")]
也在App.xaml
中:
<Style targettype="Label">
<Setter Property="FontFamily" Value="Roboto"/>
</Style>
还可以添加Entry等。 但是是否可以用一行代码更改在创建项目时初始化的默认字体系列?如果可能怎么办?
解决方法
您需要为标签,条目,选择器等创建控件。使用默认字体系列。我为您创建了一个标签控件
public class MyFontLabel : Label
{
public MyFontLabel()
{
Style = Application.Current.Resources["FontLabelStyle"] as Style;
}
}
app.xaml中的样式
<Style x:Key="FontLabelStyle" TargetType="Label">
<Setter Property="FontFamily" Value="Roboto"/>
</Style>
在整个过程中使用它
<local:MyFontLabel Text="My Text"/>