Putting * in .Net MAUI label

salilsingh-9961 346 Reputation points
2023-10-30T06:47:59.93+00:00

Hi Team,

I am working on a .Net MAUI app (in Visual Studio 2022), Android emulator used is Pixel 5 API 33. Please provide me solution for below -

Inside a label, I need to show * in red text, at end of text (like - Enter Data *),

This label is followed by an entry control.

Please let me know the standard way how to achieve this.

Let me know if more information required on this.

Thanks,

Salil

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,870 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,546 Reputation points Microsoft Vendor
    2023-10-31T07:08:19.7566667+00:00

    Hello,

    You can use FormattedText to achieve this.

    Please refer to the Use formatted text and sample code below:

    <HorizontalStackLayout>
        <Entry Placeholder="please enter data here"/>
        <Label>
            <Label.FormattedText>
                <FormattedString>
                    <Span Text="Enter Data "/>
                    <Span Text="*" TextColor="Red"/>
                </FormattedString>
            </Label.FormattedText>
        </Label>
    </HorizontalStackLayout>
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments