Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7596669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:58:25+00:00 2026-05-30T21:58:25+00:00

In a Windows Phone project I have the following scenario: The user types some

  • 0

In a Windows Phone project I have the following scenario:

  1. The user types some text in a textbox
  2. The user presses a button which disables the textbox and starts a process
  3. Some processing of the text is done and on every step of the processing I want to highlight certain part of the text in the textbox (the text itself does no change).
  4. The textbox is enabled after the processing is complete.

What is the right way to do this?

Currently I have tried to set some selection background and set the selected text using the textbox Select method but there is no visual indication of the selection even when the textbox is enabled. The SelectedText property returns the correct selected text but at least in the emulatior nothing changes visually.

Here is the code I use that does not work:
XAML

<TextBox Name="txtTest" AcceptsReturn="True" Height="250" TextWrapping="Wrap" SelectionBackground="Red"></TextBox>
<Button Name="btnTest" Width="200" Click="btnTest_Click">Test</Button>

Code behind

private void btnTest_Click(object sender, RoutedEventArgs e)
{
    txtTest.Select(1, 1);
    //on this line SelectedText has the correct value
}

I am open to other ways to do this. I don’t really want to use the selection since semantically this is not a selection but I felt it was the easiest way to achieve what I want. I may use other means to highlight specific characters for example making the font size bigger. I may also hide the textbox and replace it with a TextBlock that looks the same but I feel like there should be easier way to achieve this.

So what is the right way to implement this functionality?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:58:26+00:00Added an answer on May 30, 2026 at 9:58 pm

    After a research I found out that the Select method on a TextBox only provides visual indication if the TextBox has focus. The TextBox cannot have focus when it is not disabled so it was of no use to me. The RitchTextBox is read only and the API to select parts of the text is more complex than the solution I used.

    I used a TextBlock with the following code to highlight the text:

    private void SetTextBlock(TextBlock textBlock, string text, int selectedIndex)
    {
        textBlock.Inlines.Clear();
        Run previous = new Run();
        previous.Text = text.Substring(0, selectedIndex);
        Run current = new Run();
        current.Text = text.Substring(selectedIndex, 1);
        current.Foreground = new SolidColorBrush(Colors.Green);
        current.FontWeight = FontWeights.ExtraBold;
        Run next = new Run();
        next.Text = text.Substring(selectedIndex + 1, text.Length - selectedIndex - 1);
        textBlock.Inlines.Add(previous);
        textBlock.Inlines.Add(current);
        textBlock.Inlines.Add(next);
    }
    

    When I am processing the input I make the TextBox invisible and the TextBlock visible. When the user is providing input I switch the two. I am not sure if this is the right way to do it and I am open to other solutions but so far this is the easiest I have found.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a windows phone project where I have some xml files with
I have a sample windows phone 7 project where I test some MVVM stuff,
I have a WP7 (Windows Phone 7) project that I am working on which
I have a MonoTouch project using some code I share with a Windows Phone
I have a windows phone 7 project with a page that has the following
I am creating a windows phone application, which need to store some data in
I have The following problem: I use facebook-c#-sdk for windows phone 7.1(mango version), taken
i have to implement push notification in my project. It has sender(windows phone window
In a Windows Phone 7 project, I'm doing a color animation on a button
I have a List<PublicGrouping<DateTime,Event>> used in a LongListSelector for a windows phone 7 project.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.