Forum General

In UWP, How to apply color for a particular character in a string which is displayed in the Textbox

EswaranEswaran INMember ✭✭
edited July 2019 in General

My requirement is I like to display some string in the textbox control and I want to apply color for a particular character in a string.
Please give me a possible suggestion to achieve my requirement.
Like the image displayed below:


  • XamtasticXamtastic Member ✭✭✭
                                        <Span Text="My " TextColor="Red" />
                                        <Span Text="Label" TextColor="Blue" />
  • TedRogersTedRogers USMember ✭✭✭✭

    Here is what I have found to work. You can specify different foreground colors for each .

                <TextBlock Grid.Row="1" HorizontalAlignment="Center">
                        <Run Text="{x:Bind Name}" FontWeight="SemiBold"/>
                        <Run Text="Some other text"/>
  • EswaranEswaran INMember ✭✭

    Hi @TedRogers ,

    I have developed the custom control using Textbox control which doesn't support Run like in TextBlock control. So please suggest me any possible solution for the TextBox control.

  • TedRogersTedRogers USMember ✭✭✭✭

    @Eswaran That is much more difficult if you want to allow editing of the text. The only thing I can think of is to have a display mode where you display stylized text in a TextBlock and an edit mode where you display the un-stylized text in a TextBox. Maybe search around for a third-party control.

Sign In or Register to comment.