xamarin.forms - 应用程序资源无法使用静态资源/静态扩展
问题描述
再会!我正在使用 Prism 7.2 和 Xamarin.Forms 4.2,并且我正在尝试将外部资产用于字体。我已经在我的应用程序资源上定义了它们并在我的 xaml 代码上使用了它,但是,当我尝试使用静态扩展名作为结合{x:Static}
的值时,它也有一个静态资源扩展名,文本似乎不起作用。下面是我正在使用的代码。Text
Style
{StaticResource}
<prism:PrismApplication.Resources>
<ResourceDictionary>
<OnPlatform x:Key="LineAwesomeFontFamily" x:TypeArguments="x:String">
<On Platform="Android" Value="line-awesome.ttf#LineAwesome"/>
<On Platform="iOS" Value="lineawesome"/>
</OnPlatform>
<Style x:Key="LineAwesomeFonts"
TargetType="Label">
<Setter Property="FontFamily"
Value="{StaticResource LineAwesomeFontFamily }" />
</Style>
<Style TargetType="Button">
<Setter Property="BackgroundColor" Value="Green"/>
</Style>
</ResourceDictionary>
</prism:PrismApplication.Resources>
在视图中调用它
<Label Text="{x:Static fonts:LineAwesomeFonts.Adjust}"
Style="{StaticResource LineAwesomeFonts}"
TextColor="Black">
</Label>
如果我尝试不同的方式
<Label x:Name="testLabel"
FontSize="28" TextColor="Black">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="line-awesome.ttf#LineAwesome"/>
</OnPlatform>
</Label.FontFamily>
</Label>
并调用 testLabelxaml.cs
以使其具有可以工作的值。
知道我在做什么错吗?编译时没有发现任何错误。
解决方案
好吧,这是我的错。
public App(IPlatformInitializer platformInitializer) : base(platformInitializer)
{}
protected override void OnInitialized()
{
InitializeComponent(); //moved this away from App constructor and put it here
NavigationService.NavigateAsync("Test");
}
虽然这很奇怪,因为我InitializeComponent();
在另一个项目上是在App
构造函数上,并且资源按预期工作。
推荐阅读
- javascript - JavaScript 数组过滤器(与数组元素无关的条件)
- laravel - 如何获取 laravel-admin 网格查询和搜索条件
- python - Python:将系列附加到数据框不会将数据放在正确的列中
- vue.js - 不了解 Vuex
- sql - 将缺少的时间范围添加到选择查询(sql server)中
- android-studio - 如何将回收器查看器+按钮放在一个布局中
- python-3.x - 解释 K-Means cluster_centers_ 输出
- python - 如何将 Python 列表转换为 sympy Add 类?
- r - 检查坐标点是否落在一条线上
- assembly - 如何声明一个临时变量和一个缓冲区以在汇编语言中对字符串执行按位运算?