【发布时间】:2019-11-26 18:06:24
【问题描述】:
我最近更新到了最新的 Xamarin 表单预发布 4.2 版本。我遇到的一个值得注意的重大变化是 - 假设我有以下样式:
<Style x:Key="LightTextLabelStyle" TargetType="Label">
<Setter Property="FontFamily" Value="{StaticResource TextLight}" />
<Setter Property="FontSize" Value="15" />
<Setter Property="TextColor" Value="{StaticResource greyishBrown}" />
</Style>
在以前的版本中,跨度和标签都支持相同的目标“标签”。就像 - 这之前工作过:
<Label Margin="0,6,0,0">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding PriceText}" Style="{StaticResource LightTextLabelStyle}" FontSize="13" />
<Span Text="{Binding BidAmount, StringFormat=' {0:C0}' TargetNullValue=' Pending'}" Style="{StaticResource LightTextLabelStyle}" FontSize="13" />
</FormattedString>
</Label.FormattedText>
</Label>
针对 Label 的相同样式也支持 Span。但是现在在新版本中它没有。
我的问题是: 我们可以同时支持具有相同样式的 Label 和 Span 吗?我们不能为两者都定位相同的风格吗?就像我尝试了以下但它没有编译:
<Style x:Key="LightTextLabelStyle" TargetType="Label, Span">
<Setter Property="FontFamily" Value="{StaticResource TextLight}" />
<Setter Property="FontSize" Value="15" />
<Setter Property="TextColor" Value="{StaticResource greyishBrown}" />
</Style>
请帮助我。我可以复制粘贴样式并制作两种不同的样式;有没有更好的办法?
【问题讨论】:
标签: xaml xamarin.forms xamarin.forms-styles