How to focus with keyboard when Wpf ListView is empty?

fatih uyanık 80 Reputation points


When a Listview control is full in a wpf project, when I press the tab key with the keyboard, it can get keyboard focus. But the keyboard is not focused when Listview is empty. How can I get the ListView to focus when navigating with the tab key even when it's empty?


Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,694 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,480 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Hui Liu-MSFT 46,961 Reputation points Microsoft Vendor

    Hi,@fatih uyanık. Welcome Microsoft Q&A.

    By default, WPF controls like ListView do not receive focus when they are empty. This behavior is intentional and helps improve the user experience by avoiding confusion and ensuring that the user only interacts with controls that are currently usable.

    You could use the following code to override this behavior and allow the ListView to receive focus when it is empty.

    <Window ...
            <TextBox Text="hello" Height="100" Width="100" Background="Aquamarine"/>
            <ListView Name="lv" Focusable="True" Height="100" >
                    <Style TargetType="ListView">
                            <Trigger Property="IsFocused" Value="True">
                                <Setter Property="Background" Value="Red"/>


      private void ListView_PreviewKeyDown(object sender, KeyEventArgs e)
                if (e.Key == Key.Tab)
                    e.Handled = true;

    The result:

    User's image

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. fatih uyanık 80 Reputation points


    Didn't quite get what I wanted. My window has three buttons and a ListView. ListView doesn't get focus when empty when navigating from buttons with tab. i.e. I wanted the buttons to focus while the ListView was moving towards it. How can I do that?


  3. fatih uyanık 80 Reputation points


    Is there any solution about this? I have not yet achieved the desired result.

    0 comments No comments

  4. don bradman 621 Reputation points

    To get the ListView to focus when navigating with the tab key in a WPF project, even when it is empty, you can set the IsTabStop property of the ListView to true, and set the TabIndex property of each control to ensure that the buttons and the ListView can both be in focus.

    Here is an example:

    <Button TabIndex="1" />
    <Button TabIndex="2" />
    <Button TabIndex="3" />
    <ListView IsTabStop="True" TabIndex="4" />

    Hope this is what you're looking for.

    0 comments No comments