Xamarin.forms 应用程序资源无法使用静态资源/静态扩展
你好!我正在使用Prism 7.2和Xamarin.Forms 4.2,并且我正在尝试使用字体的外部资源。我已经在我的应用程序资源中定义了它们,并在我的xaml代码中使用了它们,但是,当我尝试使用静态扩展名{x:static}作为文本的值,并使用同样具有静态资源扩展名{StaticResource}的样式时,文本似乎不起作用。下面是我正在使用的代码Xamarin.forms 应用程序资源无法使用静态资源/静态扩展,xamarin.forms,prism,Xamarin.forms,Prism,你好!我正在使用Prism 7.2和Xamarin.Forms 4.2,并且我正在尝试使用字体的外部资源。我已经在我的应用程序资源中定义了它们,并在我的xaml代码中使用了它们,但是,当我尝试使用静态扩展名{x:static}作为文本的值,并使用同样具有静态资源扩展名{StaticResource}的样式时,文本似乎不起作用。下面是我正在使用的代码 <prism:PrismApplication.Resources> <ResourceDictionary>
<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>
并调用xaml.cs上的testLabel,使其具有一个可以工作的值
知道我做错了什么吗?编译时没有发现错误。好的,这是我的错
public App(IPlatformInitializer platformInitializer) : base(platformInitializer)
{}
protected override void OnInitialized()
{
InitializeComponent(); //moved this away from App constructor and put it here
NavigationService.NavigateAsync("Test");
}
虽然这很奇怪,因为我的初始化组件;另一个项目是在应用程序构造函数上,资源按预期工作