在 Maui 标签中将粗体文本与绑定文本连接

问题描述 投票:0回答:1

我正在尝试连接 Maui 标签中的文本,我希望部分文本为粗体。我发现的示例似乎主要针对 wpf 而不是 Maui。 这给了我连接的文本:

    <Label
        x:Name="SecondTip"
        FontSize="16" 
        VerticalOptions="Center" 
        HorizontalOptions="Start"
        Text="{Binding FirstActionRowText, StringFormat='Recommendation: {0}'}"
    />

但是如何将“推荐:”设置为粗体?我一直在尝试将 TextType 设置为 Html 并添加 Bold 标签但没有成功。 也对我如何格式化绑定文本感兴趣?

编辑:我已经实现了这样的粗体格式:

        <Label x:Name="SecondTip">
            <Label.FormattedText>
                <FormattedString>
                    <Span Text="Recommendation: " FontAttributes="Bold" FontSize="16" />
                    <Span Text="{Binding FirstActionRowText}" FontSize="16" />
                </FormattedString>
            </Label.FormattedText>
        </Label>

然而,结果给我的文本比创建普通标签和设置文本时的文本略小,所以看起来有点奇怪。如何匹配默认标签的样式?

format label maui bold
1个回答
0
投票

根据您的代码,您可以尝试将字符间距设置得更大或更小,就像:

<Span Text="Recommendation: " FontAttributes="Bold"
 CharacterSpacing="-0.5"     FontSize="16"  />

希望对你有用。

© www.soinside.com 2019 - 2024. All rights reserved.