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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:30:09+00:00 2026-05-26T00:30:09+00:00

Possible Duplicate: Select ListBoxItem if TextBox in ItemTemplate gets focus I have a ListView

  • 0

Possible Duplicate:
Select ListBoxItem if TextBox in ItemTemplate gets focus

I have a ListView bound to an ObservableCollection (Listview.ItemsSource). The listview presents several textboxes that are bound to properties of the objects in the observable collection.

I would like to have the following functionality: when a user focusses a textbox the corresponding item in the listview should get selected.

I have tried things with ContainerFromElement, ContainerFromItem, etc. but can’t get this “simple” functionality to work.

Any ideas…

  • 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-26T00:30:10+00:00Added an answer on May 26, 2026 at 12:30 am

    The trick here is to use the IsKeyboardFocusWithin property on the ItemContainerStyle:

    <ListView ItemsSource="{Binding}">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Style.Triggers>
                    <Trigger Property="IsKeyboardFocusWithin" Value="True">
                        <Setter Property="IsSelected" Value="True" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ListView.ItemContainerStyle>
        <ListView.ItemTemplate>
            <DataTemplate>
                <TextBox Text="{Binding Path=YourPropertyValue}" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    

    In this example we are simply stating that IsSelected should be set to true whenever a control within that item contains the keyboard focus.

    Note: this does not work in the opposite direction; selecting a particular item in the list will not automatically give focus to the contained TextBox

    Edit in response to comments

    As Joep pointed out, this will mean that losing keyboard focus (which will happen when a control besides the TextBox gains focus) will cause the IsSelected property to be reset to false. You can work around this by replacing the Style setter with an trigger enter action, which prevents the change from being undone when the trigger is no longer valid.

    For this to work in the same way as the previous example you will need to explicitly set the SelectionMode for the ListView to Single; otherwise, multiple items can become selected at once.

    <ListView ItemsSource="{Binding}" SelectionMode="Single">
       <ListView.ItemContainerStyle>
           <Style TargetType="ListViewItem">
               <Style.Triggers>
                   <Trigger Property="IsKeyboardFocusWithin" Value="True">
                       <Trigger.EnterActions>
                           <BeginStoryboard>
                               <Storyboard>
                                   <BooleanAnimationUsingKeyFrames
                                      Storyboard.TargetProperty="IsSelected">
                                      <DiscreteBooleanKeyFrame KeyTime="0:0:0" 
                                         Value="True" />
                                   </BooleanAnimationUsingKeyFrames>
                               </Storyboard>
                           </BeginStoryboard>
                       </Trigger.EnterActions>
                   </Trigger>
               </Style.Triggers>
           </Style>
       </ListView.ItemContainerStyle>
       <!-- ... -->
    </ListView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How disable Copy, Cut, Select, Select All in UITextView I have some
Possible Duplicate: SELECT INTO using Oracle I have one table in my oracle database.
Possible Duplicate: how to select columns as rows? I have a table with ID's,
Possible Duplicate: saving data in iOS Do we have a provision profile to select
Possible Duplicate: How does Facebook Sharer select Images? i have a blog with some
Possible Duplicate: How does Facebook Sharer select Images? Hi I have added following meta
Possible Duplicate: How does Facebook Sharer select Images? I have implemented the Facebook Like
Possible Duplicate: How does Facebook Sharer select Images? Want to have share thumbnail when
Possible Duplicate: How to get all options of a select using Jquery? I have
Possible Duplicate: Select values of checkbox group with jQuery In HTML I have a

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.