Highlight text when clicking back on box

2 posts, 0 answers
  1. Russ
    Russ avatar
    14 posts
    Member since:
    Aug 2012

    Posted 03 Mar 2014 Link to this post

    I am using the rest of the AutoCompleteBox without issues. I do have one issue.  After a user is finished making a selection and comes back later to use the Box again, they click on the box, but the 'old' text is still there.  Is there a way to have AutoCompleteBox highlight all the text in the box when it gets the focus again?  Right now it just puts the cursor at the end of the line.


  2. Kalin
    Kalin avatar
    1364 posts

    Posted 06 Mar 2014 Link to this post

    Hello Russ,

    You can achieve the desired behavior by getting the WatermarkTextBox from the AutoCompleteBox template and setting its SelectionOnFocus property to SelectAll. However you would need to do in the Loaded event handler of the AutoCompleteBox. So if you have the following AutoCompleteBox:

    <telerik:RadAutoCompleteBox Loaded="auto_Loaded" x:Name="auto" ItemsSource="{Binding Items}" SelectionMode="Single" />

    The Loaded handler should look like shown below:

    private void auto_Loaded(object sender, RoutedEventArgs e)
        var textBox = this.auto.ChildrenOfType<RadWatermarkTextBox>().First();
        textBox.SelectionOnFocus = SelectionOnFocus.SelectAll;

    This way the text will be highlighted whenever the AutoCompleteBox got the focus.

    Hope this helps.


    DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Back to Top