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>
But it appears like "My Company (spaces) (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>
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}}" />
You can specify the Spacing
property on the StackLayout
:
<StackLayout Grid.Row="1" Orientation="Horizontal" Spacing="0">
<Label x:Name="lbCo"
Text="My Company"
Style="{DynamicResource LargeLabel}"/>
<Label x:Name="lbcopywrite"
Text="©"
Margin="0,-7,0,0"
Style="{DynamicResource SmallLabel}"/>
</StackLayout>
By default, the value is 6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With