xaml - 使用 OnPlatform 时,无法让标签在 ResourceDictionary 中工作的 FontSize
问题描述
使用时,<Style TargetType="Label">
我无法让 FontSize 与 NamedSize 一起使用。
使用 Xamarin.Forms 版本:3.4.0.1008975
在职的 :
<Style TargetType="Label">
<Setter Property="FontSize" Value="Small" />
</Style>
不工作:
<Style TargetType="Label">
<Setter Property="FontSize">
<Setter.Value>
<OnPlatform x:TypeArguments="x:String"
Android="Small"
iOS="Medium"/>
</Setter.Value>
</Setter>
</Style>
我试图将 TypeArguments 更改为<OnPlatform x:TypeArguments="NamedSize" .../>
没有成功。
我正在使用其他属性设置器<OnPlatform .../>
,它们可以正常工作。它只是字体大小。
解决方案
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App67"
x:Class="App67.MainPage">
<ContentPage.Resources>
<OnPlatform x:Key="textColor"
x:TypeArguments="Color">
<On Platform="WinPhone" Value="Red" />
<On Platform="Android" Value="Aqua" />
<On Platform="iOS" Value="#80FF80" />
</OnPlatform>
<OnPlatform x:Key="fontSize"
x:TypeArguments="Font">
<On Platform="WinPhone" Value="Bold,Large" />
<On Platform="Android" Value="Bold,Large" />
<On Platform="iOS" Value="Bold,Large" />
</OnPlatform>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout>
<Label Text="Check out my style." TextColor="{StaticResource textColor}" Font="{StaticResource fontSize}" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
推荐阅读
- cakephp - 尝试在 cakephp2.x 中配置 mpdf 插件
- javascript - Laravel - PHP - 无法在单个视图中切换两个表单
- azure - Azure 中的存储消耗报告
- google-maps - MapView 的自定义信息窗口
- javascript - 将 websocket 事件转换为 observables
- stm32 - 启用流后 DMA_SxNDTR 将自身设置为最大值 (65535)
- java - AndroidX jetifier:无法使用转换 JetifyTransform 转换文件“android-all-9-robolectric-4913185-2.jar”以匹配属性
- mysql - 无法在 cPanel 上的“实时”mySQL 数据库上更新/插入或删除
- android - 将自定义音频流写入android中的麦克风流(具有root权限)
- intellij-idea - 在 IntelliJ 运行控制台上记录颜色