Mix bold text to plain text in labels

前端 未结 3 602
太阳男子
太阳男子 2021-01-27 07:36

I save my text data in a sqlite database, I am able to store them, read them and etc.

To load it in The app I do something like this in

相关标签:
3条回答
  • 2021-01-27 07:47

    I guess you cannot store a formatted text in your data base. There is no way for it to what I know. However, you can format your text for the label using the FormattedText property of the Label and setting FormattedString.

    Refer Xamarin documentation here for more details.

    Refer below example code.

    <Label LineBreakMode="WordWrap">
        <Label.FormattedText>
            <FormattedString>
                <Span Text="Hello Name, " TextColor="Red" FontAttributes="Bold" />
                <Span Text="Welcome to , " Style="{DynamicResource BodyStyle}" />
                <Span Text="Xamarin Forms." FontAttributes="Italic" FontSize="Small" />
            </FormattedString>
        </Label.FormattedText>
    </Label>
    

    As of now the only way to store formatted text in your database would be to format it using HTML and save it. You can use the Display HTML feature of Label to render that in UI. Documentation details here.

    Refer below code more reference.

    <Label Text="This is &lt;strong style=&quot;color:red&quot;&gt;HTML&lt;/strong&gt; text." TextType="Html"  />
    
    <Label TextType="Html">
        <![CDATA[
        This is <strong style="color:red">HTML</strong> text.
        ]]>
    </Label>
    
    0 讨论(0)
  • 2021-01-27 07:49

    If you trying to store and Read a single string into your SQLite DB then use TextType="Html" property in Label control.

    like...

    <Label Text="{Binding YourViewModelStringProperty}" TextType="Html">
    
    0 讨论(0)
  • 2021-01-27 07:53

    Hello @Riccardo Raffini,

    You can store Text in DB like this, "Neque <strong>porro</strong>"

    then in Xaml Add Text Type to Html,

    <Label Text="YourTextHere" TextType="Html">
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题