Xamarin表单样式-支持多种目标类型 [英] Xamarin Forms Styles - Support multiple target types

查看:99
本文介绍了Xamarin表单样式-支持多种目标类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新了最新的Xamarin表格4.2之前的版本.我遇到的一个值得注意的重大变化是-说我具有以下样式:

I have recently updated to very latest Xamarin forms pre release 4.2 version. One notable breaking change I have encounter is - Say I have the following Style:

    <Style x:Key="LightTextLabelStyle" TargetType="Label">
        <Setter Property="FontFamily" Value="{StaticResource TextLight}" />
        <Setter Property="FontSize" Value="15" />
        <Setter Property="TextColor" Value="{StaticResource greyishBrown}" />               
    </Style>

在以前的版本中,跨度和标签均支持相同的目标标签".就像-以前曾经工作过:

In previous versions, same target "Label" was supported for both Span and Labels. Like - this was working before:

    <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>

Span也支持以Label为目标的相同样式.但是现在没有新版本了.

Same style targeted for Label was support on Span as well. However now in new version it doesn't.

我的问题是: 我们可以同时支持相同样式的Label和Span吗?我们不能同时针对两种样式吗?就像我尝试了以下操作,但无法编译:

My Question is: Can we support Both Label and Span with same style? Can we not target same style for both? Like I tried the following but it doesn't compile:

    <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>

请帮助我.我可以复制粘贴样式,但是制作2种不同的样式;如果有更好的方法?

Please help me. I can copy paste the style and make 2 different styles however; if there's a some better way?

推荐答案

到目前为止,最好的解决方案是为Label和Span创建两个不同的样式.较早的Xamarin表单对两者都支持相同的样式,但现在不支持. 所以我最终有了:

So far the best solution is to create two different Styles for Label and Span. Earlier Xamarin forms supported same style for both but not now. So I ended up with having:

<Style x:Key="LightTextLabelStyle" TargetType="Label">
   <Setter Property="FontFamily" Value="{StaticResource TextLight}" />
   <Setter Property="FontSize" Value="15" />
   <Setter Property="TextColor" Value="{StaticResource greyishBrown}" />               
</Style>

<Style x:Key="LightTextSpanStyle" TargetType="Span">
   <Setter Property="FontFamily" Value="{StaticResource TextLight}" />
   <Setter Property="FontSize" Value="15" />
   <Setter Property="TextColor" Value="{StaticResource greyishBrown}" />               
</Style>

这篇关于Xamarin表单样式-支持多种目标类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆