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 1038751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:00:52+00:00 2026-05-16T15:00:52+00:00

I have seen this question: How to keep WPF TextBox selection when not focused?

  • 0

I have seen this question:

How to keep WPF TextBox selection when not focused?

And have implemented the solution there, so that my textbox shows the selection, even when it does not have focus.

However, when I change the selection start or length, nothing changes visually in the textbox. Also, when I scroll the textbox programatically and it does not have focus, the selection brush does not move with the text as it scrolls.

  • 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-16T15:00:53+00:00Added an answer on May 16, 2026 at 3:00 pm

    If you define a separate focus scope in XAML to maintain the selection (see StackPanel below) and you set the focus in the TextBox once (in this case when the Window opens using FocusManager.FocusedElement) then you should see your selection change programatically.

    Here is some sample code to get you started:

    <Window x:Class="RichTextFont2.Views.MainView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Main Window" 
      Height="400" Width="400" 
      FocusManager.FocusedElement="{Binding ElementName=myTextBox}"
      FontSize="20">
    
      <DockPanel>
        <Grid>
          <Grid.RowDefinitions>
              <RowDefinition Height="60"/>
              <RowDefinition/>
          </Grid.RowDefinitions>
          <TextBox x:Name="myTextBox" 
                   Grid.Row="0" 
                   Text="Text that does not loose selection." 
                   TextWrapping="Wrap" 
                   VerticalScrollBarVisibility="Auto">
          </TextBox>
          <StackPanel Grid.Row="1" FocusManager.IsFocusScope="True">
            <Button Content="Select Text" Click="Button_Click_MoveTextBox"/>
          </StackPanel>
        </Grid>
      </DockPanel>
    </Window>
    

    Here is some code to handle the button click event:

    private void Button_Click_MoveTextBox(object sender, RoutedEventArgs e)
    {
       if (myTextBox.SelectionStart >= myTextBox.Text.Length)
       {
          myTextBox.SelectionStart = 0;
       }
       else
       {
          myTextBox.SelectionStart += 9;
       }
       myTextBox.SelectionLength = 6;
       myTextBox.LineDown();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen there is no question that specifically reply to this combination of
I have seen this question that talks about getting the last part of a
I have seen many answers for this type of question but its not related
(Note: I have seen this question and it uses a cursor not an animation.)
I have seen this question and its answers and they clear up some of
I have seen this question about deploying to WebSphere using the WAS ant tasks.
In Microsoft SQL Server: I have seen this question several times, but can't see
Recently I have seen this code in a WebSite, and my question is the
This question may seem a little bit stackoverflow-implementation specific, but I have seen a
This question seems to have been asked a lot, but I haven't seen an

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.