【发布时间】:2020-06-05 09:38:40
【问题描述】:
我在我的解决方案(android 和 ios)中添加了 FontAwesome 字体,我可以在 xaml 中毫无问题地使用它。
我的 xaml 代码
<Label x:Name="Star1" Text="" FontSize="22" FontFamily="{StaticResource FontAwesomeRegular}"/>
App.xaml
<OnPlatform x:TypeArguments="x:String"
x:Key="FontAwesomeSolid">
<On Platform="Android"
Value="FontAwesome5Solid.otf#Regular" />
<On Platform="iOS"
Value="FontAwesome5Free-Solid" />
</OnPlatform>
<OnPlatform x:TypeArguments="x:String"
x:Key="FontAwesomeRegular">
<On Platform="Android"
Value="FontAwesome5Regular.otf#Regular" />
<On Platform="iOS"
Value="FontAwesome5Free-Regular" />
</OnPlatform>
我想在点击时更改某些标签中的 fontfamily 和 Text 值。我尝试了以下代码,但没有工作。
TapGestureRecognizer starEvent = new TapGestureRecognizer();
starEvent.Tapped += (sender, e) => {
Star1.FontFamily = Application.Current.Resources["FontAwesomeSolid"].ToString();
Star1.Text = "\uf005";
};
Star1.GestureRecognizers.Add(starEvent);
Application.Current.Resources["FontAwesomeSolid"].ToString() 返回我
“Xamarin.Forms.OnPlatform`1[System.String]”
【问题讨论】:
标签: c# xamarin xamarin.forms