Xamarin(XAML)如何并排放置2个标签 [英] Xamarin (XAML) how to place 2 labels side by side

查看:119
本文介绍了Xamarin(XAML)如何并排放置2个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个标签需要使用不同的字体来制作单个标签 我的公司(c)"(文案符号). 我的公司"将是大字体,(c)"是小字体.我无法让它们显示为1个单一标签.似乎存在间距问题.我尝试了以下方法.

I have 2 labels that need to use different fonts to make single label this "My Company (c)" (copywrite symbol). "My Company " will be a Large font and the '(c)' a small font. I can't get them to appear as 1 single label. There seems to be spacing issues. I have tried the following.

   <StackLayout Grid.Row="1" Orientation="Horizontal">
                  <Label
                      x:Name="lbCo" 
                      Text="My Company"
                      Style="{DynamicResource LargeLabel}"/>

                  <Label
                      x:Name="lbcopywrite" 
                      Text="©"
                      Margin="0,-7,0,0"
                      Style="{DynamicResource SmallLabel}"/>
                 </StackLayout>

但是它看起来像"我的公司(空格)(c)"

有什么主意如何使它看起来像我的公司(c)",并且始终在同一行上?

Any ideas how can make it look like "My Company(c)", always on the same line and together?

推荐答案

还有另一种方法,但是您不能直接为文本分配样式,但是可以选择许多字体选项.不过,您仍然可以将样式设置为主标签.

There is another way, but you can't assign a Style directly to the text, but you can choose numerous font options. You can still set a Style to the main label though.

<Label>
    <Label.FormattedText>
        <FormattedString>
            <Span Text="Company" FontAttributes="Bold"/>
            <Span Text=" ©" FontSize="Micro" />
        </FormattedString>
    </Label.FormattedText>
</Label>

如果要绑定,则需要创建一个Converter,该Converter返回FormattedString,然后分配给FormattedText.如果要重用具有不同样式的参数,可以创建带参数的Converter.

If you want binding, you need to create a Converter, that returns a FormattedString, and assign to FormattedText. You could create a Converter with Parameters if you want to reuse it, with different styles.

<Label FormattedText="{Binding Text, Converter={StaticResource FormattedStringConverter}}" />

这篇关于Xamarin(XAML)如何并排放置2个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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